[R] Save multiple plots of model output

arun smartpink111 at yahoo.com
Wed Sep 18 16:40:36 CEST 2013


Hi,
Try:
lapply(paste0("m",1:2),function(x) {png(file=paste0("plot",x,".png")); plot(get(x),pages=1,shade=TRUE);dev.off()})


#change 1:2 accordingly

A.K.


I wanted to plot a gam object output  and save the plots in a folder. I have several such objects in the workspace and wanted to automate the 
process. For a single object I would have used: 
  
png(file='plotm1.png') 
plot(m1,pages=1, shade=TRUE) 
dev.off() 

I would like to save the plot as the name of the gam object for later identification 

Example data and code 

library(MASS) 
library(mgcv) 
library(car) 

data(Prestige) 

Prestige2<-na.omit(Prestige) 

m1<-gam(prestige~s(income)+s(education),data =Prestige2) 
m2<-gam(prestige~s(income),data =Prestige2) 

Thanks



More information about the R-help mailing list