geom_point with many data points, the file size of the plot is too big.

Viewed 836

I have a scatter plot with many data points in it. Once I try to zoom in or save it in a pdf format, it takes a long time to open and the pdf is too large. How can I reduce the file size or make the plot lighter by keeping the same visuality of the plot. Here is an example:

library(ggplot2)
df <- data.frame(x = rnorm(50000),y=rnorm(50000))
ggplot(df,aes(x=x,y=y)) + geom_point()
1 Answers

Not sure what you mean with visibility. But what about the following?

library(ggplot2)
df <- data.frame(x = rnorm(50000),y=rnorm(50000))
ggplot(df,aes(x=x,y=y)) + geom_point()
ggsave('C:/yourpath/test.png', dpi = 600)

This should result in a .png file of roughly 85 kb.

If you want to increase the quality of the picture, you can increase dpi into 1200 or higher.

Related