[R] Windows, OSX and Linux: updating a graphic device and double buffering

Adrian Waddell adrian at waddell.ch
Fri Jun 11 18:28:21 CEST 2010


Hello there,

I'm struggling with the base graphics system on different
operating systems.

I would like to get an animation effect by re-plotting with the plot 
function. See the attached code example: move the slider
quick from one side to the other.

I experience different levels of success, depending on which OS I use.

- Linux (Ubuntu >9.10, R 2.9.2-3): Each plot command gets displayed.
However the labels are flickering.

- Windows: works perfect, double buffering is really well implemented.

- OS X: Moving the slider slowly results in displaying the output of
almost all plot commands. However if you move the slider quickly, only 
few of the plot commands get displayed (the orange bullet jumps).

This question has been asked before, but hopefully things have changed: 
Is it possible to double buffer my output manually?

If not, is it possible to force update my graphic device. E.g. with a 
command like dev.flush()?

How can I run my code on all operating systems without any "jumps"?

Regards,

Adrian Waddell


Here is a minimal example code:

library(tcltk)
tt <- tktoplevel()
tkpack(top <- tkframe(tt), side = "top")
SliderValue <- tclVar("50")
SliderValueLabel <- tklabel(top,text=as.character(tclvalue(SliderValue)))
tkpack(tklabel(top,text="Slider Value : "),SliderValueLabel, side = "left")
tkconfigure(SliderValueLabel,textvariable=SliderValue)
slider <- tkscale(tt, from=0, to=100,
		showvalue=F, variable=SliderValue,
		resolution=1, orient="horizontal", length = 200)
tkpack(slider, side = "top")
tkconfigure(slider, command=function(...){
			state <- unlist(...)
			myPlotFn(state)
		})

myPlotFn <- function(state) {
	plot(1,1, type = 'n', xlim = c(-10,110), ylim = c(-2,2))
	lines(c(0,100), c(0,0), lwd=4)
	points(as.numeric(tclvalue(SliderValue)),0, cex = 10, pch = 19, col = 
"orange")
}



More information about the R-help mailing list