Reduce size of plots in EPS format
Asked Answered
B

6

5

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.

Bonne answered 22/7, 2009 at 7:34 Comment(0)
M
3

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

Mady answered 22/7, 2009 at 9:30 Comment(0)
L
3

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

Laskowski answered 22/7, 2009 at 9:14 Comment(0)
M
3

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

Mady answered 22/7, 2009 at 9:30 Comment(0)
Y
2

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!

Yhvh answered 9/9, 2009 at 14:17 Comment(1)
Both links are downNag
V
2

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

Vaud answered 28/4, 2011 at 6:40 Comment(0)
I
1

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.

Ionogen answered 22/7, 2009 at 7:40 Comment(1)
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.Bonne
H
1

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.

Halloran answered 27/10, 2011 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.