View source: R/jj_arrange_ggplots.R
jj_arrange_ggplots | R Documentation |
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)
jj_arrange_ggplots(
gg_list,
nplots = 4,
cols = 2,
legend.pos = NULL,
equal_size_plots = TRUE
)
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 |
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.