Skip to content
Prev 157139 / 398506 Next

Changing a plot

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.

Sam Stewart
On Wed, Sep 24, 2008 at 11:12 AM, Ben Bolker <bolker at ufl.edu> wrote: