title: How to save a plot made with ggplot2 as SVG
body: <p>I want to save a stacked area plot (Plot example with code can be found <a href="https://stackoverflow.com/questions/12196529/how-to-name-sections-on-x-axis-that-are-seperated-by-vertical-lines-in-an-r-plot">here</a>) made with <strong>ggplot2</strong> as <strong>SVG</strong>. Tried it with the <strong>Cairo package</strong> but the outcome is bad.</p>
  
  <pre><code>library(ggplot2)
  library(grid)
  library(Cairo)
  ...
  
  #png(output_file, width=800, height=400)
  Cairo(800,400,file=paste(output_file, ".svg", sep=""),type="svg",bg="transparent",pointsize=8, units="px",dpi=400)
  
  gt &lt;- ggplot_gtable(ggplot_build(p))
  gt$layout$clip[gt$layout$name=="panel"] &lt;- "off"
  grid.draw(gt)
  
  dev.off()
  </code></pre>