p <- vplot(mtcars, width = 8, height = 3.4) |>
mark_point(x = wt, y = mpg) |>
facet_wrap(~cyl) |>
labs(title = "Weight vs. mpg, faceted by cylinder count")Faceting
facet_wrap() splits the data into a panel per group, sharing scales so the panels are directly comparable.
Strip labels
The labeller argument controls the strip text. label_both names the variable alongside its value, which a grid of bare numbers badly needs.
p_grid <- vplot(mtcars, width = 8, height = 4.4) |>
mark_point(x = wt, y = mpg) |>
facet_grid(am ~ cyl, labeller = label_both) |>
labs(title = "facet_grid() with label_both")Long values can wrap onto several lines with label_wrap_gen(width), and the strips grow to fit. A named character vector works as a lookup table.
cars <- transform(
mtcars,
trans = ifelse(am == 1, "manual gearbox, driver shifts", "automatic gearbox")
)
p_wrap <- vplot(cars, width = 8, height = 3.4) |>
mark_point(x = wt, y = mpg) |>
facet_wrap(~trans, labeller = label_wrap_gen(18)) |>
labs(title = "label_wrap_gen(18)")A legend per panel
Colour is shared across panels by default, so one legend covers the figure. When each panel holds its own set of categories, resolve_scale(color = "independent") trains the colour scale per panel, spending the whole palette on that panel’s levels, and draws each panel’s legend right beside it. To collect them in the legend area instead, give the guide a side, e.g. guides(color = guide_legend(position = "right")); each legend is then titled with its panel’s strip.
p_indep <- vplot(mtcars, width = 8, height = 3.4) |>
mark_point(x = wt, y = mpg, color = factor(gear)) |>
facet_wrap(~cyl, ncol = 3, labeller = label_both) |>
resolve_scale(color = "independent") |>
labs(color = "gears", title = "An independent colour scale in each panel")


