[R] Drawing to a buffer (or double buffering)

Manfred Georg mgeorg at cse.wustl.edu
Sat Nov 17 18:03:43 CET 2007


Hi,

I know this topic has come up several times, but I still haven't
found a satisfactory solution to it.
I want to draw complicated figures (preferably in X11) and display
them only once they are completed.
Obviously, the main purpose for doing this is so that a sequence
of complicated plots can be shown (so a solution which destroys the
window and creates a new one is not acceptable).

So far, I've played with RGtk2, cairoDevice, lattice, and grid,
but not found anything that solves the problem (what I tried is at
the bottom).  But cairo is ugly and slow at plotting images
(which is what I need to do), so I can't really use it, even
if it were to work for the buffering problem.

It looked like RGdkPixbuf maybe was able to do this,
but it seems RGtk is deprecated and not in CRAN.

Just for completeness.  This is the sort of thing I want to do.

for(iter in 1:10) {
   par(mfrow=c(20,30),mar=c(0,0,0,0))
   for(sample in 1:600) {
     image(matrix(rnorm(100),ncol=5),axes=FALSE)
   }
   Sys.sleep(1)
}

And the behavior I don't want, is the slowly filling of the plot.
I need it to be completely replaced immediately.

The only way I know of doing this is to output to png devices and
then sift through the pictures.  That is very unappealing.

Manfred

P.S. The closest I've come was:

library("RGtk2")
library("cairoDevice")
win <- gtkWindow(show=FALSE)
gtkWindowResize(win,800,600)
da <- gtkDrawingArea()
win$add(da)
win$visible <- TRUE
asCairoDevice(da)
win$visible <- FALSE
plot.new()
par(mfrow=c(2,2))
plot(1:10)

# more plot commands

win$visible <- TRUE



More information about the R-help mailing list