Ups, I just realized that we have the possibility of using grid.remove(..., redraw = FALSE) which is more or less what I was looking for.
But I'm still wondering if its possible to remove a viewport from a viewport tree: ##============================================================================== f <- function(vpName) { pushViewport(viewport(width = 0.8, height = 0.8, name = vpName)) grid.rect() } grid.newpage() f("vp1") f("vp2") f("vp3") current.vpTree() ## viewport[ROOT]->(viewport[vp1]->(viewport[vp2]->(viewport[vp3]))) ## remove("vp2") should result in ## viewport[ROOT]->(viewport[vp1]->(viewport[vp3])) ## or ## viewport[ROOT]->(viewport[vp1]) ## grid.rect should also be removed from the device ##============================================================================== is this possible? -----Ursprüngliche Nachricht----- Von: r-help-boun...@r-project.org im Auftrag von Unternährer Thomas Gesendet: Di 21.07.2009 14:18 An: r-help@r-project.org Betreff: [R] animated grid graphics I need to make a fairly complex animated graphic and decided to use grid for it. A very simple example of what I need: ##============================================================================== library(grid) grid.newpage() pushViewport(plotViewport()) pushViewport(viewport(xscale = extendrange(c(0, 100)), yscale = extendrange(c(0, 100)))) grid.xaxis() grid.yaxis() rectNames <- paste("r", 1:100, sep = "") for (i in 1:100) { grid.rect(x = unit(sample(0:100, 1), "native"), y = unit(sample(0:100, 1), "native"), width = 0.1, height = 0.1, name = rectNames[i]) } for (i in 1:100) { grid.remove(rectNames[i]) } ##============================================================================== The problem here is that removing grid objects is very slow, at least in the way I use it. Is it possible to remove all objects at once (or to use some technique similar to double buffering)? A second way to do it would be to remove a viewport and all its children from the current viewport tree. Is this possible? Example: ##============================================================================== grid.newpage() pushViewport(plotViewport()) pushViewport(viewport(xscale = extendrange(c(0, 100)), yscale = extendrange(c(0, 100)))) grid.xaxis() grid.yaxis() pushViewport(viewport(xscale = extendrange(c(0, 100)), yscale = extendrange(c(0, 100)), name = "plotVP")) for (i in 1:100) { grid.rect(x = unit(sample(0:100, 1), "native"), y = unit(sample(0:100, 1), "native"), width = 0.1, height = 0.1, name = paste("r", i, sep = "")) } *remove("plotVP")*?? ##============================================================================== Another approach would be to save every single plot as an image and use something like imagemagick to produce an animated gif, but I was just wondering if it's possible by using grid only (no need to use it outside of R). Thanks in advance Thomas ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.