Question

I have a histogram with several hundred items, for which I do a Q-Q plot. This results in EPS that is 2.5 megabytes large. This is too much for a figure that is only going to be included in a publication and is not going to be viewed at 100x magnification.

Is there any option in R to somehow output smaller EPS? I have searched docs to no avail. Or is my best option to, say, rasterize it afterwards at 300 dpi? If that's the case, any recommendations for the tool for this job?

The R code for the plot is nothing fancy:

postscript(filename)
qqnorm(n, main=title))
qqline(n)
dev.off()

EDIT: Doh! My question mentioned outputting EPS, and then converting it to some raster format. When of course I could just generate PNG in the first place from R.

Was it helpful?

Solution

I've just tried several things that didn't work - I'm including them here to save others wasting their time. For reference, I set n <- rnorm(1e5) in your code above.

Things that don't work:

  1. Setting colormodel <- "gray".

  2. Using a different value of pch. (Some other values increase the file size, but I found none that decrease it.)

  3. Setting useKerning = FALSE.

  4. Changing the width and height settings.

  5. Using pdf instead of postscript.

  6. Using CarioPS from the Cairo package.

In the light of this, I think that you are unlikely to be able to decrease the file size using a vector format. This means that you will have to use a raster format (most likely PNG).

OTHER TIPS

You have three options.

  1. Accept the large file size
  2. Save the file in a non-vector format like png
  3. Create the QQplot on a random sample of the data. A random sample of a few hundred points should give a similar QQplot.

    postscript(filename) Samp <- sample(n, size = 200) qqnorm(Samp, main=title)) qqline(Samp) dev.off()

In this discussion at the R-list link text I learned about pdftk. With n= 1e5 reduced the pdf size from 6mb to 600k. Pretty neat!

in GS view, convert our files to pdf, then convert to PS or EPS again, final file's size is reduced 5-7 times.

Well, EPS just contains instructions to draw the plot, so its size would greatly depend on how many data points you have. It's likely smaller in a PDF where compression is used but your best bet might probably be to use a raster format, which can get smaller than that.

I would suspect the EPS R generates is already as small as it can get (I'm sure they have an own function in Postscript to handle plotting the data with a one-char name, etc. as that is fairly common practice). I doubt there are many ways in which to optimize that. I might be mistaken, though, but chances are that R is the only program which has enough high-level information to reasonably compress the output.

The OP solved the problem by generating a PNG file directly. I had to use EPS because PNG and other formats aliased the image. I would have to convert to EPS anyway to include into a LaTeX file.

I used GIMP to import the 10 MB eps file generated from R image function. Then rotated, flattened, and saved as a 300KB eps file. Flattening merges all layers into a single layer and removes the alpha channel for transparency. Easily handled by LaTeX after this transformation.

Before transformation the image rendered very slowly in Ghost Script and couldn't be rendered at all in epsviewer. GIMP uses Ghost Script as a front end, so import is slow, but, once imported, all processing and rendering was very fast.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top