Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot with ggplot2: pdf very slow to display

Tags:

r

pdf

ggplot2

I am producing a pdf plot with this kind of command:

ggplot(df, aes(sample = x))+ 
        stat_qq(geom="point",distribution=qexp)+
        geom_abline(intercept = 0, slope = 1,linetype='dashed',col='red')

ggsave(file="xxx.pdf")

Than I want to integrate the pdf into a tex file and produce a final pdf document. But, the ggplot is very slow to display and makes the pdf crash very often. When I use geom='line' it doesn't happen so I guess it comes from the number of circle points. Do you have any idea on how to solve this? I really prefer the geom='point' option.

like image 350
mlal Avatar asked Sep 14 '25 10:09

mlal


1 Answers

PDFs are vector based - so every single point on your chart has to be loaded individually. This produces a 'load-up' sort of effect on your PDF. My solution would be to save as a high DPI png/gif instead:

ggsave(file="xxx.png", dpi=400) #default is 300 which is probably sufficent

Tex to pdflatex (or AN Other) will find the file 'xxx' if you not forced an extension in your R to Tex conversion as the include statement will usually not mention an extension. You will need to make sure that the pdf is deleted from the your charts folders to ensure it doesn't get picked up in preference to the png.

like image 189
Steph Locke Avatar answered Sep 16 '25 00:09

Steph Locke