I am trying to plot four correlation plots in a 2x2 grid using ggplot2
and gridExtra
.
I have four more or less identical plots like this:
p1 <- ggplot(d,aes(x,y)) + theme_bw() +
scale_y_continuous(name="X") +
scale_x_continuous(name="Y") +
geom_point()
The axes of each plot differ quite a bit, or I would have used facet_wrap
to plot the four correlations. Instead, I use arrangeGrob
, like this:
g <- arrangeGrob(p1,p2,p3,p4,ncol=2,nrow=2)
ggsave("correlations.pdf",g,dpi=300)
ggsave("c1.pdf",p1,dpi=300)
I have included both the saving of the grid as well as one of the plots. The grid results in a blank PDF file (with filesize ~3MB), while the individual plot works.
My suspicion/additional info: each of the plots has 270,000 observations, plotted as individual points, for a total >1,000,000. I can imagine how this might give the PDF-rendering trouble.
Can anyone confirm this, and perhaps provide a workaround? Is there a command to let geom_point
show fewer points/omit overlapping points?