Skip to contents

Styles the layers: their color (by a layer column, one per layer, or one constant), their names and the node set names, and how they are stacked and spaced. Add it to a plot made with mira().

Usage

mira_layer(
  color_by,
  color,
  color_values,
  color_scale,
  labels,
  label_size,
  set_labels,
  stack,
  spacing,
  color_palette,
  color_reverse,
  color_limits
)

Arguments

color_by

Layer column to color layers by (a column of net$layers), or "layer_name" for one color per layer (".individual" works too). NULL or NA = default.

color

A constant layer color: a color name or "#rrggbb". Give color_by or color, not both.

color_values

Colors for values of the color_by column, named by value. With color_by = "layer_name", named by layer: c(L1 = "red", L3 = "#1f77b4"); layers not listed keep MiRA's color. See mira_scales.

color_scale

"categorical" or "continuous". Not with color_by = "layer_name". See mira_scales.

labels

TRUE or FALSE: show layer names.

label_size

Layer name size, a whole number between 8 and 32 (14 = MiRA's default). Used when layer names are shown.

set_labels

TRUE or FALSE: show node set names (bipartite layout only; needs mira(..., bipartite = TRUE)).

stack

"horizontal" or "vertical": how layers are stacked.

spacing

Space between layers, a whole number between 100 and 600 (300 = MiRA's default).

color_palette

A named palette for the color_by scale: categorical ("Okabe-Ito", ...) or continuous ("magma", ...); see mira_scales for the list.

color_reverse

TRUE reverses the palette.

color_limits

c(min, max): the gradient runs from min to max instead of the data's range; values outside take the end colors. Gives a continuous scale.

Value

A component, to add to a plot with +.

Details

Layer colors are used in the network, grid and map views. In the layer view (mira_mode_layer()) the bubbles follow color_by, not a constant color. One color per layer (color_by = "layer_name") is not a scale: its colors are given with color_values, and color_scale, color_palette, color_reverse and color_limits with it are errors.

Examples

library(emln)
net <- load_emln(17) # 4 layers; bird and plant nodes
#> Creating state node map
#> Creating extended link list with node IDs
p <- mira(net, bipartite = TRUE, setA_type = "bird")
#> Bipartite network: drawn as undirected. Use directed = TRUE for a directed one.

# Color by a layer column, or one color for all
p + mira_layer(color_by = "interaction_type")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.
p + mira_layer(color = "#e5e7eb")
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.

# One color per layer, two of them set by hand
p + mira_layer(color_by = "layer_name",
               color_values = c(layer_1 = "orange", layer_3 = "#9467bd"))
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.

# Choose the colors of a column (see ?mira_scales)
p + mira_layer(color_by = "interaction_type", color_scale = "categorical",
               color_values = c("seed-dispersal" = "#17becf"))
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.

# Layer names and node set names
p + mira_layer(labels = TRUE, label_size = 18, set_labels = TRUE)
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.

# Stack the layers top to bottom, closer together
p + mira_layer(stack = "vertical", spacing = 250)
#> Not opened: R is not interactive. Print the plot in an R session, or give `browser` to open it from a script.