0

How can I export multiple plots as a pdf in R ? Does anyone know What is the command for this ?

user1769197
  • 2,132
  • 5
  • 18
  • 32
  • I ended up here before I found the other links. So just posting the links to previous/better answers: https://stackoverflow.com/questions/1395410/how-to-print-r-graphics-to-multiple-pages-of-a-pdf-and-multiple-pdfs https://stackoverflow.com/questions/7534606/save-multiple-graphs-one-after-another-in-one-pdf-file – Ajay May 10 '21 at 17:00

4 Answers4

10

You may want to try this:

pdf(file='plot.pdf')
plot(1:10)
dev.off()

Since you didn't provide any reproducible example I just give you the example written above. See the documentation by doing ?pdf and ?dev.off()

Community
  • 1
  • 1
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
3

Multiple plots would be (adding to Jilber)

pdf(file='plot.pdf')
par(mfrow=(c(1,3)))
plot(1:10)
plot(rnorm(10)
plot(rnorm(10)
dev.off()
Community
  • 1
  • 1
PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
2

or You can use the plyr package to create a pdf with multiple plots

library(ply)
pdf("plots.pdf", width = 7, height = 7)
d_ply(df, .(z), failwith(NA, function(x){plot(x$y,main=unique(z))}), .print=TRUE)
dev.off()

were df is a data frame containing a conditional factor (z) and a target variable (y). You will get as many plots as z levels, all included in a pdf report.

jrs-x
  • 336
  • 1
  • 2
  • 10
0

The above answers will help you to export the plots in table but if you want them to be in table like 2-3 graphs in 1 row, you can use following code:

pdf("Export_Plots.pdf", width = 16 , height = 10, title = "EDA Plots for data")
par(mfrow=c(2,2))
for(i in 1:10){
  par(mar = c(5,4,4,5)+.1)
  plot(i)
}

dev.off()

Please check below link for more detail: https://topbullets.com/2017/04/19/exporting-multiple-graphs-in-same-plot-to-pdf-in-r-topbullets-com/

deepeshsingh
  • 21
  • 1
  • 3