[R] Reducing the size of pdf graphics files produced with R
Joerg van den Hoff
j.van_den_hoff at fzd.de
Tue May 22 21:27:11 CEST 2007
On Tue, May 22, 2007 at 01:06:06PM -0400, Chabot Denis wrote:
> Thank you Prof. Ripley.
> Believe me, I do not have the skills to contribute such a thing as a
> stream compressor and I DO appreciate the work and usefulness of the
> pdf device as it is. I do most of my plots with pdf device, the rest
> with quartz (especially when I'm not sure I'll want to save a plot)
> and (rarely) png when the pdf output is too large or for
> compatibility with microsoft applications.
> I find the statement you took from the help page promising: I often
> include these large plots into LaTeX, so I'll investigate what form
> of compression pdftex can do.
> Le 07-05-22 à 12:47, Prof Brian Ripley a écrit :
> >> From the help page
> > 'pdf' writes uncompressed PDF. It is primarily intended for
> > producing PDF graphics for inclusion in other documents, and
> > PDF-includers such as 'pdftex' are usually able to handle
> > compression.
> > If you are able to contribute a stream compressor, R will produce
> > smaller plots. Otherwise it is unlikely to happen (and it any case
> > would be a
> > smaller contribution than that of the author of pdf(), who is quite
> > happy with external compressors).
> > Acrobat does other things (not all of which it tells you about),
> > but compression is the main advantage.
> > On Tue, 22 May 2007, Chabot Denis wrote:
> >> Hi,
> >> Without trying to print 1000000 points (see <http://
> >> finzi.psych.upenn.edu/R/Rhelp02a/archive/42105.html>), I often print
> >> maps for which I do not want to loose too much of coastline detail,
> >> and/or plots with 1000-5000 points (yes, some are on top of each
> >> other, but using transparency (i.e. rgb colors with alpha
> >> information) this actually comes through as useful information.
> >> But the files are large (not as large as in the thread above of
> >> course, 800 KB to about 2 MB), especially when included in a LaTeX
> >> document by the dozen.
> >> Acrobat (not the reader, the full program) has an option "reduce file
> >> size". I don't know what it does, but it shrinks most of my plots to
> >> about 30% or original size, and I cannot detect any loss of detail
> >> even when zooming several times. But it is a pain to do this with
> >> Acrobat when you generate many plots... And you need to buy Acrobat.
> >> Is this something the pdf device could do in a future version? I
> >> tried the "million points" example from the thread above and the 55
> >> MB file was reduced to 6.9 MB, an even better shrinking I see on my
> >> usual plots.
> >> Denis Chabot
> >> ______________________________________________
> >> 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.
> > --
> > Brian D. Ripley, ripley at stats.ox.ac.uk
> > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> > University of Oxford, Tel: +44 1865 272861 (self)
> > 1 South Parks Road, +44 1865 272866 (PA)
> > Oxford OX1 3TG, UK Fax: +44 1865 272595
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
as an attempt to suggest something more helpful than "do write the
compressor yourself if you have a problem with pdf()":
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.
More information about the R-help