Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

combine_plots

Combining and arranging multiple plots in a grid


Description

Wrapper around patchwork::wrap_plots that will return a combined grid of plots with annotations.

Usage

combine_plots(
  plotlist,
  guides = "collect",
  plotgrid.args = list(),
  annotation.args = list(),
  ...
)

Arguments

plotlist

A list containing ggplot objects.

guides

A string specifying how guides should be treated in the layout. 'collect' will collect guides below to the given nesting level, removing duplicates. 'keep' will stop collection at this level and let guides be placed alongside their plot. auto will allow guides to be collected if a upper level tries, but place them alongside the plot if not. If you modify default guide "position" with theme(legend.position=...) while also collecting guides you must apply that change to the overall patchwork (see example).

plotgrid.args

A list of additional arguments passed to patchwork::wrap_plots, except for guides argument which is already separately specified here.

annotation.args

A list of additional arguments passed to patchwork::plot_annotation.

...

Currently ignored.

Value

Combined plot with annotation labels

References

Examples

# loading the necessary libraries
library(ggplot2)

# preparing the first plot
p1 <-
  ggplot2::ggplot(
    data = subset(iris, iris$Species == "setosa"),
    aes(x = Sepal.Length, y = Sepal.Width)
  ) +
  geom_point() +
  labs(title = "setosa")

# preparing the second plot
p2 <-
  ggplot2::ggplot(
    data = subset(iris, iris$Species == "versicolor"),
    aes(x = Sepal.Length, y = Sepal.Width)
  ) +
  geom_point() +
  labs(title = "versicolor")

# combining the plot with a title and a caption
combine_plots(
  plotlist = list(p1, p2),
  annotation.args = list(
    tag_levels = "a",
    title = "Dataset: Iris Flower dataset",
    subtitle = "Edgar Anderson collected this data",
    caption = "Note: Only two species of flower are displayed"
  )
)

ggstatsplot

'ggplot2' Based Plots with Statistical Details

v0.7.2
GPL-3 | file LICENSE
Authors
Indrajeet Patil [cre, aut, cph] (<https://orcid.org/0000-0003-1995-6531>, @patilindrajeets)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.