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

From: Waichler, Scott R <Scott.Waichler_at_pnl.gov>
Date: Wed, 23 May 2007 10:13:22 -0700

Scott

Scott Waichler, Senior Research Scientist Pacific Northwest National Laboratory
MSIN K9-36
P.O. Box 999
Richland, WA 99352 USA
509-372-4423 (voice)
509-372-6089 (fax)
scott.waichler_at_pnl.gov
http://hydrology.pnl.gov



 

> -----Original Message-----
> From: Joerg van den Hoff [mailto:j.van_den_hoff_at_fzd.de]
> Sent: Wednesday, May 23, 2007 9:25 AM
> To: Waichler, Scott R
> Cc: r-help_at_stat.math.ethz.ch; j.van_den_hoff_at_fzd.de
> Subject: Re: [R] Reducing the size of pdf graphics files
> produced with R
>
> On Wed, May 23, 2007 at 07:24:04AM -0700, Waichler, Scott R wrote:
> > > 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
> `dev2bitmap(file = "rf.pdf", type = "pdfwrite")' copies the
> current device to the pdf-file `rf.pdf', i.e. you should have
> plotted something on the screen prior to using this (the
> manpage tells you so much...). no `dev.off' is necessary in this case.
>
> in order to "plot directly" into the pdffile, you can use
> `bitmap' instead of `dev2bitmap', i.e.
>
> use either:
>
> plot(1:10)
> dev2bitmap(file = "rf1.pdf", type = "pdfwrite")
>
> or:
>
> bitmap(file = "rf2.pdf", type = "pdfwrite")
> plot(1:10)
> dev.off()
>
> both should produce the desired output file (at least after
> including the correct `width' and `height' settings).

I tried the second method, using width=8.5, height=11, but the margins in the output were bad, as if it assumed a4 paper or something. I tried inserting paper="special" and paper="letter" in the bitmap call, but both caused errors. Also, the plot was in grayscale instead of color.

Scott Waichler



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 23 May 2007 - 17:18:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 May 2007 - 09:31:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.