title: Save multiple ggplots using a for loop
body: <p>I want to automate the generation of a number of ggplots:</p>
  
  <p>Generic dataset:</p>
  
  <pre><code>mydata&lt;-data.frame(matrix(rnorm(100),ncol=5))
  names(mydata)&lt;-c("Tijd","X1","X2","X3","X4") 
  </code></pre>
  
  <p>Specify variables to include:</p>
  
  <pre><code>Start=2
  Stop=5
  </code></pre>
  
  <p>List to save the plots in:</p>
  
  <pre><code>gvec&lt;-vector("list",length=length(Start:Stop))
  </code></pre>
  
  <p>Create plots:</p>
  
  <pre><code>for(i in Start:Stop){
    graphy&lt;-ggplot(mydata,aes_string(x="Tijd",y=names(mydata)[i]))+geom_point()+mytheme
    gvec[[i-Start+1]]&lt;-graphy
  }
  </code></pre>
  
  <p>Save plots:</p>
  
  <pre><code>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()
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>As per Roland's suggestion I tried
  <code>print(gvec[[i-Start+1]])</code> but I still get blank files as output. </p>