Skip to contents

Arrange plots in a regular grid. Panel alignment uses the space allocated on the graphics device when the figure is drawn.

Usage

ggplus(..., ncol = NULL, align = c("cell", "panel"), nrow = NULL, gap = NULL)

Arguments

...

Original graphics or a single unnamed list of graphics. Panel mode supports Base drawings, single-panel filling Lattice plots, single-panel ggplots, and gtables with a recognized data panel.

ncol, nrow

Number of columns and rows. Supply either one to infer the other. When both are supplied, the grid must fit all inputs. With neither supplied, the arrangement is chosen automatically.

align

Use "cell" for standard patchwork layout or "panel" to match the top and bottom data-panel edges within each row and the left and right edges within each column.

gap

Extra space between adjacent cells, in millimetres. Use one non-negative number for both directions or two numbers for horizontal and vertical spacing, optionally named x and y. The default adds no extra space. Axis labels, legends and plot margins still contribute to the distance between data panels.

Value

A patchwork composition in cell mode or a wrapped patchwork element in panel mode. Both support patchwork's +, |, and /.

Details

In cell mode, the gaps have fixed physical sizes and patchwork can adjust the plot rows and columns to respect fixed-aspect coordinates. For example, a single-panel radar chart can share its panel height with a scatter plot in the same row while keeping its circular grid.

Panel mode builds an equal-cell grid inside a single patchwork element. Apply themes, axes and other child styling before assembly. Annotations and other plots can be added around the assembled grid with patchwork. Axis ranges and tick values belong to each input.

Panel alignment normally uses one unconstrained panel per input. A row of two plots can include one fixed-aspect single-panel ggplot such as a radar chart. The companion can be a single-panel Base R, filling Lattice or unconstrained ggplot graphic. The panel heights match while the fixed-aspect plot keeps its coordinate ratio. These pairs have a small outer margin to accommodate plot labels. The grid measures again when rendered at a different size. Base formulas and callbacks run when first drawn, and the recordings are reused on subsequent draws. Base capture requires 'gridGraphics'. A panel narrower or shorter than 15 mm triggers a warning. Measurement uses the corresponding scratch backend for standard PDF, Cairo PDF, ragg PNG, svglite SVG and native Windows screen output. Other devices use standard PDF measurements.

Examples

p <- ggplot2::ggplot(women, ggplot2::aes(height, weight)) + ggplot2::geom_point()
q <- p + theme_forma()
ggplus(p, q, nrow = 1, align = "panel", gap = 4)