Wrap plots into a patchwork
While the use of +
is a natural way to add plots together, it can be
difficult to string together multiple plots programmatically if the number
of plots is not known beforehand. wrap_plots
makes it easy to take a list
of plots and add them into one composition, along with layout specifications.
wrap_plots( ..., ncol = NULL, nrow = NULL, byrow = NULL, widths = NULL, heights = NULL, guides = NULL, tag_level = NULL, design = NULL )
... |
multiple |
ncol |
The dimensions of the grid to create - if both are |
nrow |
The dimensions of the grid to create - if both are |
byrow |
Analogous to |
widths |
The relative widths and heights of each column and row in the grid. Will get repeated to match the dimensions of the grid. |
heights |
The relative widths and heights of each column and row in the grid. Will get repeated to match the dimensions of the grid. |
guides |
A string specifying how guides should be treated in the layout.
|
tag_level |
A string ( |
design |
Specification of the location of areas in the layout. Can either
be specified as a text string or by concatenating calls to |
If design
is specified as a text string and the plots are named (e.g.
wrap_plots(A = p1, ...)
) and all plot names are single characters
represented in the design layout string, the plots will be matched to their
respective area by name. Otherwise the areas will be filled out
sequentially in the same manner as using the +
operator. See the examples
for more.
A patchwork
object
library(ggplot2) 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) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) p5 <- ggplot(mtcars) + geom_violin(aes(cyl, mpg, group = cyl)) # Either add the plots as single arguments wrap_plots(p1, p2, p3, p4, p5) # Or add them as a list... plots <- list(p1, p2, p3, p4, p5) wrap_plots(plots) # Match plots to areas by name design <- "#BB AA#" wrap_plots(B = p1, A = p2, design = design) # Compare to not using named plot arguments wrap_plots(p1, p2, design = design)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.