Ggplot output results in one pdf, but several pages in R

I have at least 10 ggplot plots (we can call them plot1, plot2 ....). I can output them to separate PDF files. But I prefer to output them in only one pdf file, but several pages. One page, one plot from ggplot.

I tried to list all the graphs and use ggsave, but it cannot work. Any idea or script can help? Thanks you

+4
source share
2 answers

See the function pdffor this.

For three graphs, it will look like this (saving to your working directory with the default name). Skip the line dev.offbefore you can open the file.

pdf()
plot1
plot2
plot3
dev.off()

list1:

pdf()
list1
dev.off()
+6

aosmith, ​​ ggplot2 pdf.

GG_save_pdf = function(list, filename) {
  #start pdf
  pdf(filename)

  #loop
  for (p in list) {
    print(p)
  }

  #end pdf
  dev.off()

  invisible(NULL)
}
0

All Articles