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]]
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 >
> thanks > that was very helpful. > i have been reading and trying to modify the code around to suit, buthaven't been able to:> first, maximize the chart with the window being maximized, the way itis it stays the same size after maximizing the window. The function tkrplot has optional arguments hscale and vscale that can be used to adjust the initial size of the graph, but currently tkrplot does not do dynamic resizing. To make the plot 3 times as wide and 2 times as tall just change the tkrplot call to: img <- tkrplot(tt,f1,hscale=3,vscale=2)> second, plotting another sequence which share the same index with thefirst sequence but with different values, its scale> I wish to place on the right side of the chart.Add your code for the second series to the f1 function. Something like: 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,y2)) points(x,y2[x],type='b', col='green') axis(4) } or 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)) par(new=TRUE) plot(x,y2[x], type='b', col='green', axes=F) axis(4) } Hope this helps, [[alternative HTML version deleted]]
in regards to the dynamic resizing, one would think that commands like plot.default {package:graphics} does it, as I am exploring other commands from graphics it seams like tkrplot may not be needed, I am not sure as I just started with graphics in R, maybe a better way to go is call TclTk from R but not sure how, or even save the data to an output file and run TclTk independently. what do you think? I have done it both ways, you can see examples of using the R graphics window (which can be resized) with a Tk control box in several of the functions in the TeachingDemos package (run.cor2.examp for example). Unfortunatly when working in windows there is a tendancy for the R window to jump in front of the Tk window which I find annoying, you can get past this by running R with the SDI switch, but I favor the tkrplot approach now (The TeachingDemos examples will be changing at some point to allow either option). This is less of an issue on Unix, I have no idea about macs. This is starting to get into details rather than general R discussion so future discussion may be better as just e-mails rather than involving the discussion list. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111