简体   繁体   中英

How can I export multiple plots as a pdf in R?

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

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()

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()

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM