save multiple plots r into separate jpg
<p>Dear Stackoverflow'ers!</p>

<p>I have simple database, app. 130 variables, 1500 records and lots of similar plots to create. I try to avoid save them by hand. The for loop works perfectly for plots (in RStudio).</p>

<p><a href="https://www.dropbox.com/s/rts3zhwlta2t3ou/data.csv?dl=0" rel="nofollow">Here are the data</a> as .csv on dropbox. </p>

<pre><code>data &lt;- read.csv2("data.csv", header=TRUE)
data &lt;- select(data,v1,v2,v3,v4,v5,v6,v7)

for (i in data) {
    sjp.frq(i)
}
</code></pre>

<p>I would like to save the plots in some directory as a separate .png or .jpg files. I found some clues <a href="http://www.r-bloggers.com/automatically-save-your-plots-to-a-folder-2/" rel="nofollow">here</a>. The code looks like this:</p>

<pre><code>data &lt;- select(df,v1,v2,v3,v4,v5,v6,v7)
variables &lt;- names(data)

for (i in data) {
  png(paste0("plots/plot_",names(data)[i],".png"))
    sjp.frq(i)
  dev.off()
}
</code></pre>

<p>I deliberately simplified the sjp.frq expression to not make the code unnessecarely complicated.</p>

<p>And here's the problem. I get only single .png file in folder. Where do I make mistake? There should be seven of them.</p>

<p>Best regards, MaciejB.</p>

<p>PS. I follow the suggestion of making code reproducible and added sample of my databaase. When I use i.e. iris, it works. It seems to be something wrong with my data, some NA's maybe? But when I used na.omit() it's the same.</p>

<p>PS.2 I checked another ploting functions like hist() or plot() but it's the same. Only one plot produced and saved.</p>