[R] graphing and scrolling

Gregory Snow Greg.Snow at intermountainmail.org
Mon Mar 27 22:24:37 CEST 2006


Does the following (or some simple modification of it) do 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)





-- 
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 stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Fred J.
> Sent: Monday, March 27, 2006 1:05 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] graphing and scrolling
> 
> Dear R users
>  
>   graphing with plot(x) seams to work for a small length(x), 
> when length(x)  is too large it seams to clutter the display, 
> a solution would be to  display subsets of x at a time, yet a 
> better way which I hope R  supports is to place a sliding bar 
> on the display window to control  length(x) and thus the 
> resolution, which will involve auto scaling  the y axis as 
> well as automatically place a side-to-side scrolling bar  at 
> the bottom of the chart to move through and display the 
> subsets of  x  according  to the resolution. is there such an 
> implementation?
>  
>  thank you
>  
> 		
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list