title: Plotting by iteration in R
body: <p>I am working on a project that requires I have 20 different bar charts. I have found that I can plot them one by one, but am looking for a more efficient way to do this in the future if a similar problem comes up.</p>
  
  <p>I have tried a standard for loop, but my plots all come up empty.</p>
  
  <pre><code>    library(lattice)
      par(mfrow = c(1,1))
      b_clr &lt;- c("steelblue", "darkred")
  
  
      for(i in 1:20){
        png(paste(i,'.png', sep = ''))
  
  
      barchart(as.table(V[[i]]),
          main = map$V1[i],
          horizontal = FALSE,
          col = ifelse(V[[i]] &gt; 0,
                       b_clr[1],
                       b_clr[2]),
          ylab = "Impact Value",
          scales = list(x=list(relation = "free",
                               rot = 55,
                               labels = top.df[[i]],
                               cex = 1.1)))
      dev.off()
      }
  </code></pre>
  
  <p>If I take this out of the loop, and change all the i's to individual values, the plots work just fine. But, if I run them as a loop I get no plots. Can anyone offer any suggestions?</p>