Wilmer E. Henao
Wilmer E. Henao

Reputation: 4302

How to save a pdf in R with a lot of points

So I have to save a pdf plot with a lot of points in it. That is not a problem. The problem is that when I open it. It takes forever to plot all those points. How can I save this pdf in such a way that it doesn't have to draw point by point when someone opens it. I'm OK if the quality of the picture goes down a bit.

Here's a sample. I don't think this would crash your computer but be careful with the parameter length if you have an old machine. I am using many more points than that in my real problem by the way.

pdf("lots of points.pdf")
x <- seq(0,100, length = 100000)
y <- 0.00001 * x
plot(x, y)
dev.off()

Upvotes: 3

Views: 1985

Answers (1)

Janhoo
Janhoo

Reputation: 597

I had a similar problem and there is a sound solution. The drawback is that this solution is not generic and does not involve programming (always bad).

For draft purposes, png or any other graphic format may be sufficient, but for presentation purposes this is often not the case. So the way to go is to combine vector graphics for fonts, axis etc and bitmap for your zillions of points:

1) save as pdf (huge and nasty)

2) load into illustrator or likewise ( must have layers )

3) separate points from all other stuff by dragging other stuff to new layer - save as A

4) delete other stuff and export points only as bitmap (png, jpg) and save as B

5) load B into A; scale and move B to exact overlap; delete vector points layer, and export as slender pdf.

done. takes you 30 minutes.

As said this has nothing to do with programming, but there is simply no way around the fact that as vector graphics each and every point (even those that are not visible, since covered by others) are single elements and its a pain handling pdfs with thousands of elements. So there is need for postprocessing. I know ImageMagick can do alot, but AFAIK the above cant be done by an algorithm.

The only programming way to (partly) solve this is to eliminate those points that will not display because the are covered by others. But thats beyond me.

Only go this way if you really and desperately need extreme scalability, otherwise go with @Ben and @inform and use a bitmap --in whatever container you need it (png,pdf,bmp,jpg,tif, even eps).

Upvotes: 1

Related Questions