[R] smooth scrolling with windows() function

Greg Snow Greg.Snow at intermountainmail.org
Thu Sep 13 17:47:25 CEST 2007


I don't know why windows is so slow/jumpy doing it your way.  One
alternative is to use the tkrplot library.  This does redraw the plot
every time, but it is fast enough that it goes pretty smooth.  Here is
an example that you can start with to see if it does what you want:

library(tkrplot)

y <- rnorm(10000, 10, 2) + 5*sin( (1:10000)/1000 )

tt <- tktoplevel()
left <- tclVar(1)
oldleft <- tclVar(1)
right <- tclVar(100)

f1 <- function(){
        lleft <- as.numeric(tclvalue(left))
        rright <- as.numeric(tclvalue(right))
        x <- seq(lleft,rright,by=1)
        plot(x,y[x], type='b',ylim=range(y))
}

img <- tkrplot(tt, f1)

f2 <- function(...){
        ol <- as.numeric(tclvalue(oldleft))
        tclvalue(oldleft) <- tclvalue(left)
        r <- as.numeric(tclvalue(right))
        tclvalue(right) <- as.character(r + as.numeric(...) - ol)
        tkrreplot(img)
}

f3 <- function(...){
        tkrreplot(img)
}

f4 <- function(...){
        ol <- as.numeric(tclvalue(oldleft))
        tclvalue(left) <- as.character(ol+100)
        tclvalue(oldleft) <- as.character(ol+100)
        r <- as.numeric(tclvalue(right))
        tclvalue(right) <- as.character(r+100)
        tkrreplot(img)
}

s1 <- tkscale(tt, command=f2, from=1, to=length(y),
        variable=left, orient="horiz",label='left')
s2 <- tkscale(tt, command=f3, from=1, to=length(y),
        variable=right, orient="horiz",label='right')
b1 <- tkbutton(tt, text='->', command=f4)

tkpack(img,s1,s2,b1) 


Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Samuel Kemp
> Sent: Thursday, September 13, 2007 4:53 AM
> To: r-help at r-project.org
> Subject: [R] smooth scrolling with windows() function
> 
> Hi,
> 
> I have a large plot that I would like to display in a 
> graphics device with scroll bars. I therefore decided to use 
> the windows function like so...
> 
> mag<- length(tick)
> windows(height=mag/8, width=10, rescale="fixed")
> 
> However, when I use the scroll bars the device (i guess) is 
> re-drawing the plot. Is there any way in which I can get it 
> to 'smooth scroll'?
> 
> Kind regards,
> 
> Sam
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.
> 



More information about the R-help mailing list