0

I am using ggplot and ggplot.multiplot function to plot multiplots (2 columns plots) per page but I couldnt make it. please help

I have a list of ggplots in variable plot_list and using function ggplot2.multiplot to plot 2 plot per page. But it plot all figures in one page that messed up. I want two plot per page in single figure.

>plot_list ## ggplot saved in a list though i have long list to plot
[[1]]

[[2]]

[[3]]

[[4]]

In both case i tried but all four plots plotted in same page:

library(easyGgplot2)
library(ggplot2)
ggplot2.multiplot(plotlist = plot_list, cols=2)
ggplot2.multiplot(plotlist = plot_list)

However its work as:

ggplot2.multiplot(plot_list[[1]],plot_list[[2]],cols=2)
ggplot2.multiplot(plot_list[[3]],plot_list[[4]],cols=2)

But i have long list of figures to generate in a single pdf !!

I also i have tried library("cowplot") but got error while using list of figures.

plot_grid(plot_list, ncol = 2, nrow = 1)

Error in ggplot_to_gtable(x) : 
  Argument needs to be of class "ggplot" or "gtable"

Please help. Thanks

RKK
  • 31
  • 11
  • Are you open to using par(mfrow=c(2,2)) for the four plots you want to plot? Also, some grid.arrange function will do the trick here too probably. – InfiniteFlash Mar 22 '16 at 17:14
  • See this link for what I am talking about. http://www.statmethods.net/advgraphs/layout.html – InfiniteFlash Mar 22 '16 at 17:16
  • Where did you get that `ggplot.multiplot` function? Furthermore: It is always good to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). – Jaap Mar 22 '16 at 17:20

2 Answers2

2

there's gridExtra::marrangeGrob

library(ggplot2)
library(gridExtra)

 pl <- replicate(5, ggplot(), simplify=FALSE)
 ml <- marrangeGrob(pl, nrow=1, ncol=2)
 ggsave("multipage.pdf", ml)

enter image description here

baptiste
  • 75,767
  • 19
  • 198
  • 294
1

for your cowplot problem, there is an argument plotlist in the plot_grid function (https://rdrr.io/cran/cowplot/man/plot_grid.html):

plot_grid(plotlist=plot_list)

should work

mherold
  • 11
  • 1