facet_wrap() lays panels out in a ribbon wrapped into ncol/nrow;
facet_grid() arranges them on a 2-D grid defined by a rows ~ cols
formula. Position scales are shared across panels by default (so axes align);
pass scales = "free_x", "free_y", or "free" to train them per panel.
Colour, size and the other non-position scales are shared too (one legend);
resolve_scale(color = "independent") gives each panel its own.
Arguments
- plot
A PlotSpec.
- facets
A faceting formula. For
facet_wrap(), one-sided such as~ cyl(one or more+-separated variables); forfacet_grid(), a two-sidedrows ~ cols(use.for no faceting on a side).- ncol, nrow
Number of columns/rows for
facet_wrap().- scales
One of
"fixed"(default),"free_x","free_y","free".- labeller
How to label the facet strips: a labeller such as
label_both(),label_value()orlabel_wrap_gen(), a named character vector looking values up (c("4" = "Four")), or a function from values to labels (seeas_labeller()). The default,NULL, shows the values, several variables on one side joined by", ".
Value
The modified PlotSpec.
Examples
vplot(mtcars) |> mark_point(x = wt, y = mpg) |> facet_wrap(~cyl)
vplot(mtcars) |> mark_point(x = wt, y = mpg) |> facet_grid(am ~ cyl)
vplot(mtcars) |>
mark_point(x = wt, y = mpg) |>
facet_grid(am ~ cyl, labeller = label_both)
