[R] Reducing the size of pdf graphics files produced with R

Waichler, Scott R Scott.Waichler at pnl.gov
Wed May 23 16:24:04 CEST 2007

> as you are using MacOS X, you'll have ghostscript installed anyway. so
> try in R `dev2bitmap' with `type =pdfwrite'. I believe `gs' _does_
> include compression. a quick test showed at least a reduction by about
> a factor of 2 relative to `pdf()'. probably one can fiddle with the
> ghostscript settings (cf. e.g. `Ps2pdf.htm' in the ghostscipt 
> docs: you
> can adjust the resolution for images in the pdf file) to
> improve this, so as a last resort you could indeed export the graphics
> as postscript and do the conversion to `pdf' by adjusting the `ps2pdf'
> switches. but even with the default settings the pdf produced via
> dev2bitmap/ghostscript is the better solution. apart from file size I
> by and then ran into problems when converting `pdf()' output to
> postscript later on, for instance.

Can you give an example of dev2bitmap usage?  I tried using it in place
of a pdf() statement.  An X11 window opened and my figure flew by, but I
didn't get the file output.  I also used dev2bitmap after opening a
pdf() and just before the dev.off() statement, since the help says it
works on the "current device", but again no written output.  What am I
doing wrong?

I tried:
  dev2bitmap(file = plotfile2, type="pdfwrite", width=8.5, height=11,


  pdf(file = plotfile, paper="letter", width=8.5, height=11,
  dev2bitmap(file = plotfile2, type="pdfwrite", width=8.5, height=11,

Scott Waichler
scott.waichler _at_ pnl.gov

More information about the R-help mailing list