Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

output ggplot results in one pdf but several pages in R

Tags:

r

pdf

ggplot2

I have at least 10 plots by ggplot(we can call them plot1, plot2 ....). I can output them into 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 plots and use ggsave but it can not work. Any idea or script can help? Thank you

like image 530
cutebunny Avatar asked Dec 06 '22 21:12

cutebunny


1 Answers

See the pdf function for this.

For three plots it would look like this (saving into your working directory with default naming). Run through dev.off line before you can open file.

pdf()
plot1
plot2
plot3
dev.off()

If your plots are already stored in a list named list1:

pdf()
list1
dev.off()
like image 76
aosmith Avatar answered Dec 27 '22 19:12

aosmith