tags:

views:

724

answers:

4

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()

Thanks.

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. Thanks for all the answers.

+1  A: 

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.

Joey
PDF results in 1 mb size file, still too big. I guess I could apply dataset sampling to reduce number of points, but then it's hard not to lose a few interesting outlier points.
Laurynas Biveinis
+2  A: 

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()

Thierry
+1  A: 

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).

Richie Cotton
+1  A: 

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!

Eduardo Leoni