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).NULLorNA= default.- color
A constant layer color: a color name or
"#rrggbb". Givecolor_byorcolor, not both.- color_values
Colors for values of the
color_bycolumn, named by value. Withcolor_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 withcolor_by = "layer_name". See mira_scales.- labels
TRUEorFALSE: 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
TRUEorFALSE: show node set names (bipartite layout only; needsmira(..., 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_byscale: categorical ("Okabe-Ito", ...) or continuous ("magma", ...); see mira_scales for the list.- color_reverse
TRUEreverses the palette.- color_limits
c(min, max): the gradient runs frommintomaxinstead of the data's range; values outside take the end colors. Gives a continuous scale.
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.
See also
mira_scales for color_values and color_scale.
Other components:
mira_camera(),
mira_filter(),
mira_interlayer(),
mira_intralayer(),
mira_layout(),
mira_legends(),
mira_mode,
mira_mode_dashboard(),
mira_mode_data(),
mira_mode_grid(),
mira_mode_layer(),
mira_mode_map(),
mira_mode_meta(),
mira_node()
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.
