ggarrange: Arrange Multiple ggplots

Description Usage Arguments Value Author(s) See Also Examples

View source: R/ggarrange.R

Description

Arrange multiple ggplots on the same page. Wrapper around plot_grid(). Can arrange multiple ggplots over multiple pages, compared to the standard plot_grid(). Can also create a common unique legend for multiple plots.

Usage

1
2
3
ggarrange(..., plotlist = NULL, ncol = NULL, nrow = NULL, labels = NULL,
  align = c("none", "h", "v", "hv"), widths = 1, heights = 1,
  legend = NULL, common.legend = FALSE)

Arguments

...

list of plots to be arranged into the grid. The plots can be either ggplot2 plot objects or arbitrary gtables.

plotlist

(optional) list of plots to display.

ncol

(optional) number of columns in the plot grid.

nrow

(optional) number of rows in the plot grid.

labels

(optional) list of labels to be added to the plots. You can also set labels="AUTO" to auto-generate upper-case labels or labels="auto" to auto-generate lower-case labels.

align

(optional) Specifies whether graphs in the grid should be horizontally ("h") or vertically ("v") aligned. Options are "none" (default), "hv" (align in both directions), "h", and "v".

widths

(optional) numerical vector of relative columns widths. For example, in a two-column grid, widths = c(2, 1) would make the first column twice as wide as the second column.

heights

same as widths but for column heights.

legend

character specifying legend position. Allowed values are one of c("top", "bottom", "left", "right", "none"). To remove the legend use legend = "none".

common.legend

logical value. Default is FALSE. If TRUE, a common unique legend will be created for arranged plots.

Value

return an object of class ggarrange, which is a ggplot or a list of ggplot.

Author(s)

Alboukadel Kassambara alboukadel.kassambara@gmail.com

See Also

annotate_figure()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)

# Create some plots
# ::::::::::::::::::::::::::::::::::::::::::::::::::
# Box plot
bxp <- ggboxplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Dot plot
dp <- ggdotplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Density plot
dens <- ggdensity(df, x = "len", fill = "dose", palette = "jco")

# Arrange
# ::::::::::::::::::::::::::::::::::::::::::::::::::
ggarrange(bxp, dp, dens, ncol = 2, nrow = 2)
# Use a common legend for multiple plots
ggarrange(bxp, dp,  common.legend = TRUE)

YTLogos/ggpubr documentation built on May 3, 2019, 9:04 p.m.