mlal
mlal

Reputation: 89

ggplot with ggplot2: pdf very slow to display

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.

Upvotes: 4

Views: 3008

Answers (1)

Steph Locke
Steph Locke

Reputation: 6166

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.

Upvotes: 8

Related Questions