title: Unknown graphics device error in Rstudio
body: <p>I want to save 10 different <code>ggplots</code> to disc with different parameters, but getting the error:</p>
  
  <blockquote>
    <p>Error: Unknown graphics device ''</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>for (geneNum in 1:10) {
    geneCounts &lt;- plotCounts(dds, gene=gene_list[geneNum], 
    intgroup=c("Groups","Mouse"), returnData=TRUE)
    ggplot(geneCounts, aes(x=Mouse, y=count, color=Groups, 
    group=Groups)) +
    scale_y_log10() + geom_point(size=3) + geom_line() + 
    ggtitle(gene_list[geneNum])
    filename &lt;- paste0("gene", geneNum, sep="_")
    ggsave(filename,
       plot = last_plot(), # or give ggplot object name as in myPlot,
       width = 5, height = 5,
       units = "in", # other options c("in", "cm", "mm"), 
       dpi = 300)
  }
  </code></pre>
  
  <p>Any suggestions would be greatly appreciated.</p>