I think you have two issues here:
- You're plotting a raster image with a low pixel density (so zooming in just gives you poor quality images).
One solution is to use the ggsave() function in ggplot2 to output to scalar vector graphics (.svg).
For example:
library(ggplot2)
# Create dummy data
y=data.frame(matrix(rnorm(10000,5),ncol=2))
paste(object.size(y)/1e6,"mB")
# Save to image file
image=ggplot(data=x,aes(x=X1,y=X2))+geom_point()
# Write image to file
ggsave(filename="test.svg",plot=image,width=10,height=8,units="cm")
If you don't want an .svg file, I'd stick to a .png file. You can look at the res
attribute in png()
here
2. You're plotting something very large all at once.
This is where things get interesting. You could look at creating an image using a layered approach. That is: plot the polygons/lines/points from the large data set by their id/groupings (I'm not sure exactly how your data looks - hopefully this helps). I've given a demo for some inspiration:
# Write to .svg
enter code here
# Make dummy data
test_data=data.frame(matrix(c(1,2.5,3,3,1.5,2,2,2,1,1,3,1,0,1),ncol=2))
test_data$id=c('a','a','a','a','b','b','b')
#Plot data
plot(c(1,2),c(3,3),xlim=c(0,4),ylim=c(0,4),pch=15,col='red')
#Plot layers in big dataframe
by(test_data[,c("X1","X2")],INDICES=test_data$id,polygon)
The by() function is very handy for producing multi-layer plots. It's significantly faster than a for()
loop in R.