Reduce PDF file size in graphics in R

I draw some data in R using the following commands:

jj = ts(read.table("overlap.txt")) pdf(file = "plot.pdf") plot(jj, ylab="", main="") dev.off() 

The result is as follows:

enter image description here

The problem is that the pdf file I get is quite large (25Mb). Is there a way to reduce file size? JPEG is not an option because I need a vector drawing.

+7
source share
5 answers

Take a look at tools::compactPDF - you need to install either qpdf or ghostscript, but this can significantly affect the size of the pdf file.

+9
source

You draw a lot of lines or dots. Vector image formats, such as pdf, ps, eps, svg, etc., support logical information about all of these points, lines or other elements that increase complexity, which leads to the size and time of drawing as the number of points increases. Typically, vector images are the best in many ways, the most compact, scalable and high quality playback. But, if the number of graphic elements becomes very large, it is often better to switch to a raster image format, for example, png. When you switch to a bitmap image, it’s best to have an idea of ​​what size of the image you want, in pixels as well as in things like print dimensions, to create the best image possible.

For information from a different direction, the bitmap is too large, see this answer .

+6
source

One way to reduce the file size is to reduce the number of values ​​that you have. Assuming you have a dataframe called df :

 # take sample of data from dataframe sampleNo = 10000 sampleData <- df[sample(nrow(df), sampleNo), ] 

I think the only alternative inside R is to create a non-vector. Outside of R you can use Acrobat Professional (which is not free) to optimize pdf. This can significantly reduce file size.

+4
source

What version of R are you using? In R 2.14.0, pdf() has a compress argument to support compression. I'm not sure how much this can help you, but there are other tools for compressing PDF files, such as Pdftk and qpdf . I have two shells for them in the animation package, but you can use the command line directly.

+4
source

It's hard to say, without seeing what the plot looks like - to publish a screenshot?

I suspect that he has a lot of very detailed lines, and most of the information is probably not visible - a lot of things overlapping or the very tiniest details. Try thinning out data in one dimension. I doubt that you will lose visible information.

+1
source

All Articles