jj_arrange_ggplots: arrange ggplots in a grid

View source: R/jj_arrange_ggplots.R

jj_arrange_ggplotsR Documentation

arrange ggplots in a grid

Description

plot multiple plots together in a grid based on a list of ggplot objects The following error can occur and is related to problems with the legend. Try to change legend.pos to solve it: Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), : Viewport has zero dimension(s)

Usage

jj_arrange_ggplots(
  gg_list,
  nplots = 4,
  cols = 2,
  legend.pos = NULL,
  equal_size_plots = TRUE
)

Arguments

gg_list

list of ggplot objects

nplots

number of plots to combine together

cols

number of columns for the plot layout

legend.pos

position of legends. One of 'left','right','top','bottom','none'. If null, do not change legend positions

equal_size_plots

if TRUE, make all individual plots the same size

Examples

df = data.frame(a=rnorm(100, 0, 5), b=rnorm(100, 0, 5), d=rbinom(100, 50, 0.3), e = sample(c('A','B', 'C'), 100, replace=T))
ggl = list()
ggl[[1]] = ggplot(df, aes(x = a, y = b, colour=d)) + geom_point()
ggl[[2]] = ggplot(df, aes(x = a, y = b, colour=e)) + geom_point()
ggl[[3]] = ggplot(df, aes(x = a)) + geom_histogram()
jj_arrange_ggplots(ggl, nplots = 4, cols = 2)
jj_arrange_ggplots(ggl, nplots = 4, cols = 2, legend.pos = 'none')

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.