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?
You have a few options.
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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With