I want to automate the generation of a number of ggplots:
Generic dataset:
mydata<-data.frame(matrix(rnorm(100),ncol=5))
names(mydata)<-c("Tijd","X1","X2","X3","X4")
Specify variables to include:
Start=2
Stop=5
List to save the plots in:
gvec<-vector("list",length=length(Start:Stop))
Create plots:
for(i in Start:Stop){
graphy<-ggplot(mydata,aes_string(x="Tijd",y=names(mydata)[i]))+geom_point()+mytheme
gvec[[i-Start+1]]<-graphy
}
Save plots:
for(i in Start:Stop){
tiff(paste0("Test/Residu/Plots/Prei/mydata.",names(mydata)[i],"09.14.tiff"),width=720,height=720)
gvec[[i-Start+1]]
graphics.off()
}
The list of plots is generated; I can save the plots manually as well. However, using the last loop the files generated are all blank. I can't figure out the reason for this.
As per Roland's suggestion I tried
print(gvec[[i-Start+1]])
but I still get blank files as output.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…