Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R graph quality

Tags:

graph

plot

r

pdf

Is there a way to optimize the graph quality from R?

I have 30 million data points, and I generated a Q–Q plot and saved it as a PDF file using:

pdf(myPlot.pdf)
qqnorm(X)
dev.off()

But the PDF file size is so big that I can not even open it to view!

Is there a way either saving this with a lower quality or as a different type (I don't necessarily need PDF) so I can view the graph?

like image 533
user1007742 Avatar asked Feb 13 '26 06:02

user1007742


1 Answers

You have a few options.

  1. Don't plot all the points. Compare:

    X = rnorm(1e5)
    qqnorm(X, xlim=c(-4.5, 4.5), ylim=c(-4.5, 4.5))
    qqnorm(X[seq(1, length(X), 5)], xlim=c(-4.5, 4.5), ylim=c(-4.5, 4.5))
    qqnorm(X[seq(1, length(X), 10)], xlim=c(-4.5, 4.5), ylim=c(-4.5, 4.5))
    

    I would suggest it's almost impossible to visually notice a difference

  2. Don't use the pdf plotting device. Instead try png or jpeg. These functions have a resolution argument, res, that controls the plotting resolution. So something like this should do the trick:

    ppi = 300
    png("mygraph.png", width=6*ppi, height=6*ppi, res=ppi)
    qqnorm(X)
    dev.off()
    
like image 90
csgillespie Avatar answered Feb 15 '26 18:02

csgillespie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!