To control how different plots are laid out, you need to add a layout design specification. If you are nesting grids, the layout is scoped to the current nesting level.
Arguments
- ncol, nrow
The dimensions of the grid to create - if both are
NULL
it will use the same logic asfacet_wrap()
to set the dimensions- byrow
If
FALSE
the plots will be filled in in column-major order.- widths, heights
The relative widths and heights of each column and row in the grid. Will get repeated to match the dimensions of the grid. The special value of
NA
will behave as1null
unit unless a fixed aspect plot is inserted in which case it will allow the dimension to expand or contract to match the aspect ratio of the content.- design
Specification of the location of areas in the layout. Can either be specified as a text string or by concatenating calls to
area()
together.- guides
A string with one or more of
"t"
,"l"
,"b"
, and"r"
indicating which side of guide legends should be collected. Defaults towaiver()
, which inherits from the parent layout. If there is no parent layout, or ifNULL
is provided, no guides will be collected.
Examples
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear))
p3 <- ggplot(mtcars) +
geom_bar(aes(gear)) +
facet_wrap(~cyl)
align_plots(p1, p2, p3) +
layout_design(nrow = 1L)
align_plots(p1, p2, p3) +
layout_design(ncol = 1L)