Changing a plot
R Help wrote:
Thanks, I looked into the grid package. The grid package does do a
better job of managing the plotting, but it's still re-plotting the
entire canvas whenever a modifcation is made to a plot.
I guess I should have been a little clearer with my question. Here's
a sample function.
library(tcltk)
x = runif(10000)
y = runif(10000)
v1 <- viewport()
grid.rect(gp = gpar(lty = "dashed"))
pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
pushViewport(dataViewport(x, y))
grid.rect()
grid.xaxis()
grid.yaxis()
grid.points(x, y)
grid.text("1:10", x = unit(-3, "lines"), rot = 90)
v2 <- viewport()
push.viewport()
grid.points(x[1],y[1],pch=16,gp=gpar(col='green'),name='pts')
index = tclVar(1)
grid
refresh <- function(...){
i <- as.numeric(tclvalue(index))
grid.edit('pts',x=unit(x[i],'npc'),y=unit(y[i],'npc'))
}
m <- tktoplevel()
pScale <- tkscale(m,from=0,to=10000,orient='horiz',resolution=1,variable=index,command=refresh)
tkgrid(pScale)
The green point should change as the slider is moved, but there are so
many points in the background that replotting them confuses the
graphic. What I want to be able to do is replt the green point
without removing the background.
The TK canvas is rather good at replotting only what is necessary. Unfortunately, it lacks functionality for a real graphics driver, but you might want to look into demo(tkcanvas).
O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907