l_facet: Layout Facets across multiple panels

View source: R/l_facet.R

l_facetR Documentation

Layout Facets across multiple panels

Description

It takes a loon widget and forms a matrix of loon widget facets.

Usage

l_facet(widget, by, on, layout = c("grid", "wrap", "separate"), ...)

## S3 method for class 'loon'
l_facet(
  widget,
  by,
  on,
  layout = c("grid", "wrap", "separate"),
  connectedScales = c("cross", "row", "column", "both", "x", "y", "none"),
  linkingGroup,
  nrow = NULL,
  ncol = NULL,
  inheritLayers = TRUE,
  labelLocation = c("top", "right"),
  labelBackground = "gray80",
  labelForeground = "black",
  labelBorderwidth = 2,
  labelRelief = c("groove", "flat", "raised", "sunken", "ridge", "solid"),
  plotWidth = 200,
  plotHeight = 200,
  parent = NULL,
  ...
)

## S3 method for class 'l_serialaxes'
l_facet(
  widget,
  by,
  on,
  layout = c("grid", "wrap", "separate"),
  linkingGroup,
  nrow = NULL,
  ncol = NULL,
  labelLocation = c("top", "right"),
  labelBackground = "gray80",
  labelForeground = "black",
  labelBorderwidth = 2,
  labelRelief = c("groove", "flat", "raised", "sunken", "ridge", "solid"),
  plotWidth = 200,
  plotHeight = 200,
  parent = NULL,
  ...
)

Arguments

widget

A loon widget

by

loon plot can be separated by some variables into mutiple panels. This argument can take a vector, a list of same lengths or a data.frame as input.

on

if the by is a formula, an optional data frame containing the variables in the by. If variables in by is not found in data, the variables are taken from environment(formula), typically the environment from which the function is called.

layout

layout facets as 'grid', 'wrap' or 'separate'

...

named arguments to modify the 'loon' widget states

connectedScales

Determines how the scales of the facets are to be connected depending on which layout is used. For each value of layout, the scales are connected as follows:

  • layout = "wrap": Across all facets, when connectedScales is

    • "x", then only the "x" scales are connected

    • "y", then only the "y" scales are connected

    • "both", both "x" and "y" scales are connected

    • "none", neither "x" nor "y" scales are connected. For any other value, only the "y" scale is connected.

  • layout = "grid": Across all facets, when connectedScales is

    • "cross", then only the scales in the same row and the same column are connected

    • "row", then both "x" and "y" scales of facets in the same row are connected

    • "column", then both "x" and "y" scales of facets in the same column are connected

    • "x", then all of the "x" scales are connected (regardless of column)

    • "y", then all of the "y" scales are connected (regardless of row)

    • "both", both "x" and "y" scales are connected in all facets

    • "none", neither "x" nor "y" scales are connected in any facets.

linkingGroup

A linkingGroup for widgets. If missing, default would be a paste of "layout" and the current tk path number.

nrow

The number of layout rows

ncol

The number of layout columns

inheritLayers

Logical value. Should widget layers be inherited into layout panels?

labelLocation

Labels location.

  • Length two vector for layout grid. The first one is used to determine the position of column labels ('top' or 'bottom'). The second one is used to determine the position of row labels ('right' or 'left').

  • Length one vector for layout wrap, 'top' or 'bottom'.

labelBackground

Label background colour

labelForeground

Label foreground colour

labelBorderwidth

Label border width

labelRelief

Label relief

plotWidth

default plot width (in pixels)

plotHeight

default plot height (in pixels)

parent

a valid Tk parent widget path. When the parent widget is specified (i.e. not NULL) then the plot widget needs to be placed using some geometry manager like tkpack or tkplace in order to be displayed. See the examples below.

Value

an 'l_facet' object (an 'l_compound' object), being a list with named elements, each representing a separate interactive plot. The names of the plots should be self explanatory and a list of all plots can be accessed from the 'l_facet' object via 'l_getPlots()'.

Examples

if(interactive()) {
  library(maps)
  p <- with(quakes, l_plot(long, lat, linkingGroup = "quakes"))
  p["color"][quakes$mag < 5 & quakes$mag >= 4] <- "lightgreen"
  p["color"][quakes$mag < 6 & quakes$mag >= 5] <- "lightblue"
  p["color"][quakes$mag >= 6] <- "firebrick"
  # A Fiji map
  NZFijiMap <- map("world2", regions = c("New Zealand", "Fiji"), plot = FALSE)
  l_layer(p, NZFijiMap,
          label = "New Zealand and Fiji",
          color = "forestgreen",
          index = "end")
  fp <- l_facet(p, by = "color", layout = "grid",
                linkingGroup = "quakes")

  size <- c(rep(50, 2), rep(25, 2), rep(50, 2))
  color <- c(rep("red", 3), rep("green", 3))
  p <- l_plot(x = 1:6, y = 1:6,
              size = size,
              color = color)
  g <- l_glyph_add_text(p, text = 1:6)
  p['glyph'] <- g
  on <- data.frame(Factor1 = c(rep("A", 3), rep("B", 3)),
                   Factor2 = rep(c("C", "D"), 3))
  cbind(on, size = size, color = color)
  fp <- l_facet(p, by = Factor1 ~ Factor2, on = on)
}

if(interactive()) {

# serialaxes facets
s <- l_serialaxes(iris[, -5], color = iris$Species)
fs <- l_facet(s, layout = "wrap", by = iris$Species)
# The linkingGroup can be printed or accessed by
l_configure(s, linkingGroup = fs[[1]]['linkingGroup'], sync = "pull")
}

loon documentation built on July 9, 2023, 5:48 p.m.