Hello list, Could the following be done without too much grief...? Lets say I have two or three time series objects that I want to inspect visually. Each I would plot with a y-offset so they stack up. They share the same X scaling. The problem is that each is perhaps 100K values. Due to the large number of values, features of the data sets cannot be seen when all values are plotted. What would be nice is to plot a fraction of the X range (say 10%). This would be equivalent to zooming in the X direction. Then using a key (ideally an arrow key), shift the viewing frame right or left to effectively scroll through the data. So first you view 0-10%, then 10-20% and so forth. If necessary I can fabricate a vector with X values in it and plot(x,y) instead of as time series, if this makes it any easier. I am using a Windows version of R. Thanks, =Randy= R. Zelick email: zelickr at pdx.edu Department of Biology voice: 503-725-3086 Portland State University fax: 503-725-3888 mailing: P.O. Box 751 Portland, OR 97207 shipping: 1719 SW 10th Ave, Room 246 Portland, OR 97201
x-only zoom and pan?
5 messages · Randy Zelick, Jason Turner, Peter Wolf +1 more
Could the following be done without too much grief...?
It sounds possible, but there are already packages that deal with these issues. Some suggestions: 1) Use SVG plots, and Adobe's SVG Viewer plug-in for various web browsers. See the RSvgDevice package for details. 2) Use the Java graphics device - though under Windows, getting SJava working can be problematic. http://www.omegahat.org/RJavaDevice/ Cheers Jason
Hallo here is a simple proposal using tcltk-sliders.
Peter Wolf
# step 1: define general slider function
slider<-function(refresh.code,names,minima,maxima,resolutions,starts,title="control",no=0,
set.no.value=0){
# pw 03/2004
if(no!=0)
return(as.numeric(tclvalue(get(paste("slider",no,sep=""),env=slider.env))))
if(set.no.value[1]!=0){
try(eval(parse(text=paste("tclvalue(slider",set.no.value[1],")<-",
set.no.value[2],sep="")),env=slider.env));
return(set.no.value[2]) }
if(!exists("slider.env")) slider.env<<-new.env()
library(tcltk); nt<-tktoplevel(); tkwm.title(nt,title);
tkwm.geometry(nt,"+0+0")
for(i in seq(names))
eval(parse(text=paste("assign(\"slider",i,"\",tclVar(starts[i]),env=slider.env)",sep="")))
for(i in seq(names)){
tkpack(fr<-tkframe(nt)); lab<-tklabel(fr, text=names[i], width="25")
sc<-tkscale(fr, command=refresh.code, from=minima[i], to=maxima[i],
showvalue=T, resolution=resolutions[i], orient="horiz")
assign("sc",sc,env=slider.env); tkpack(lab,sc,side="right")
eval(parse(text=paste("tkconfigure(sc,variable=slider",i,")",sep="")),env=slider.env)
}
tkpack(fr<-tkframe(nt),fill="x")
tkpack(tkbutton(fr, text="Exit",
command=function()tkdestroy(nt)),side="right")
tkpack(tkbutton(fr, text="Reset", command=function(){
for(i in seq(starts))
eval(parse(text=paste("tclvalue(slider",i,")<-",starts[i],sep="")),env=slider.env)
refresh.code() } ),side="left")
}
# step 2: define function for zooming
ts.zoom<-function(x,y,z){
# pw 05042004
library(tcltk)
n.ts<-1; if(!missing(y)) n.ts<-2; if(!missing(z)) n.ts<-3
refresh.code<-function(...){
# initialization
start<-slider(no=1)*100; delta<-slider(no=2)*100
if(start+delta>length(x))
start<-slider(set.no.value=c(1,(length(x)-delta)/100))*100
# plot
par(mfrow=c(n.ts,1))
plot(x,type="l",xlim=c(start,start+delta))
if(n.ts>=2) plot(y,type="l",xlim=c(start,start+delta))
if(n.ts>=3) plot(z,type="l",xlim=c(start,start+delta))
par(mfrow=c(1,1))
}
slider(refresh.code,
# names of sliders
c("begin index (unit=100)", "window width (unit=100)"),
# min of sliders
c(0,1),
# max of sliders
c(floor(length(x)/100),length(x)/100),
# step of sliders
c(1,1),
# initial values
c(1,1))
}
# step 3: test it.
ts.zoom(runif(10000), rexp(10000), rnorm(10000))
Randy Zelick wrote:
Hello list, Could the following be done without too much grief...? Lets say I have two or three time series objects that I want to inspect visually. Each I would plot with a y-offset so they stack up. They share the same X scaling. The problem is that each is perhaps 100K values. Due to the large number of values, features of the data sets cannot be seen when all values are plotted. What would be nice is to plot a fraction of the X range (say 10%). This would be equivalent to zooming in the X direction. Then using a key (ideally an arrow key), shift the viewing frame right or left to effectively scroll through the data. So first you view 0-10%, then 10-20% and so forth. If necessary I can fabricate a vector with X values in it and plot(x,y) instead of as time series, if this makes it any easier. I am using a Windows version of R. Thanks, =Randy= R. Zelick email: zelickr at pdx.edu Department of Biology voice: 503-725-3086 Portland State University fax: 503-725-3888 mailing: P.O. Box 751 Portland, OR 97207 shipping: 1719 SW 10th Ave, Room 246 Portland, OR 97201
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
"Peter" == Peter Wolf <s-plus at wiwi.uni-bielefeld.de>
on Mon, 05 Apr 2004 10:41:24 +0200 writes:
Peter> Hallo here is a simple proposal using tcltk-sliders.
Peter> Peter Wolf
Peter, that is interesting (and nice in its generality and programming
interface),
however for a bit more intuitive *user* interface,
I slightly prefer the way I have done it for the 'tkdensity' function
I made (from Peter Dalgaard's original tkdensity demo).
Try
install.package("sfsmisc")
example(tkdensity)
Regards,
Martin
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
"MM" == Martin Maechler <maechler at stat.math.ethz.ch>
on Mon, 5 Apr 2004 18:43:53 +0200 writes:
"Peter" == Peter Wolf <s-plus at wiwi.uni-bielefeld.de>
on Mon, 05 Apr 2004 10:41:24 +0200 writes:
Peter> Hallo here is a simple proposal using tcltk-sliders.
Peter> Peter Wolf
MM> Peter, that is interesting (and nice in its generality and programming
MM> interface),
MM> however for a bit more intuitive *user* interface,
MM> I slightly prefer the way I have done it for the 'tkdensity' function
MM> I made (from Peter Dalgaard's original tkdensity demo).
MM> Try
MM> install.package("sfsmisc")
MM> example(tkdensity)
and of course, that needs a
library(sfsmisc)
between the installation and the example call...
Thank you, Uwe {and "how embarassing..."}!
Martin