Plotting large plots in R can be painfully slow. I'm trying some workarounds but even with the maximally-buffered "dbcairo" X11 device, plotting seems to take much longer than it could. I noticed that the "png" device is faster for both small plots and large plots.
Small plots, png() beats X11() by about 3x:
> system.time({X11(type="dbcairo"); plot(1:1e3); dev.off()})
user system elapsed
0.234 0.029 0.373
> system.time({png("file.png",type="cairo"); plot(1:1e3); dev.off()})
user system elapsed
0.114 0.000 0.113
> system.time({png("file.png",type="Xlib"); plot(1:1e3); dev.off()})
user system elapsed
0.056 0.000 0.107
Large plots, png() beats X11() by 2.3x to 46x:
> system.time({X11(type="dbcairo"); plot(1:1e5); dev.off()})
user system elapsed
14.420 0.157 15.491
> system.time({png("file.png",type="cairo"); plot(1:1e5); dev.off()})
user system elapsed
6.790 0.001 6.826
> system.time({png("file.png",type="Xlib"); plot(1:1e5); dev.off()})
user system elapsed
0.144 0.010 0.340
The results were pretty much the same with other X11() device types (being similar to "dbcairo") and other bitmap image types (being similar to "png"). I'm guessing png() type "cairo" takes longer than "Xlib" because it produces antialiased output.
With a medium-sized ggplot2 plot, I found that png() is 1.7x to 2.6x faster than X11() (that's using png(..); plot(g); dev.off(), not ggsave())
Since I can load and reload a PNG file almost instantaneously using a minimalist image-viewer like "feh", I'm wondering why I don't use png() as my primary plotting device with R.
The problem of course is that the PNG file isn't written to disk until I call dev.off(). This crimps the style of the standard plotting interface, where I set the device once and then bring up various plots, sometimes adding lines or text, while viewing each change immediately in the plot window.
Would it be difficult to create a new R graphics device which writes image files to PNG (or some other image format), but uses a simple image viewer like "feh" to display them after each plotting command? In other words, I'm looking for an "interactive" plotting device like X11, but which uses the bitmap off-screen rendering facilities of existing devices such as png(), jpeg(), or tiff() to draw the image. Or maybe the png() device can be modified to have an option which gives it this behavior. (Or maybe I should be using knitR for everything ... but I am more familiar with the command line ...)