Here is the same using the playwith package: library(playwith) playwith(plot(1:20, (1:20)^cur.time), time.vector=seq(0.05,2,by=0.05))
When you click on the plot, the location (in plot coordinates) is shown inside the window. However, I must admit that this is somewhat of a special case, and in fact the "time.vector" and "time.mode" are not really intended to be used this way. I would like to make it easy to add widgets like sliders, numeric inputs and toggles, that are linked to variables in the plot. This is currently possible but more complicated than is warranted. Felix On Fri, Jun 13, 2008 at 5:37 PM, <[EMAIL PROTECTED]> wrote: > > Hi Sebastian, > > The package rpanel (see www.stats.gla.ac.uk/~adrian/rpanel/) makes it really > easy to embed plots into tcltk widgets. > > > Try the following in R: > > #---------------------------------------------------------------------------------------- > install.packages("rpanel") > require(tkrplot) > library(rpanel) > my.action<-function(panel,x,y){print(c(x,y)); return(panel)} > rpplot <- rp.control(title = "Demonstration of rp.tkrplot", h = 1) > > redraw <- function(panel) { > rp.tkrreplot(panel, tkrp) > } > > rp.tkrplot(rpplot, tkrp, function(panel) plot(1:20, > (1:20)^panel$h),action=my.action) > rp.slider(rpplot, h, action = redraw, from = 0.05, to = 2.00, resolution = > 0.05) > #---------------------------------------------------------------------------------------- > > > When you left click on the plot the function "my.action" prints the x,y pixel > coordinates of the point you clicked in the graph. I have written functions > in the past which map the pixel coordinates to the grpahical user coords. > Then it picks out the nearest point. > > This is still slightly messy though! It is not possible to generalise the > process of mapping pixel coordinates with the graphical user coords. It can > depend on the settings of the users PC etc. > > The developers of rpanel are aware of this and may, in the future, build a > locator function in the rpanel package. > > I hope this helps. > > Regards > > Wayne > > > > > > > > > > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Sebastian P. > Luque > Sent: 13 June 2008 04:14 > To: r-sig-gui@stat.math.ethz.ch > Subject: [R-gui] embedding R graphics in Tk widgets > > > Hi, > > Several years ago I was looking for ways to embed R graphics into Tk > widgets, and abandoned the idea after finding out it was way too > difficult, at least for my purposes. More recently, I looked again and > found Luke Tierney's trkplot, which allows one to do just this. > However, there seem to be limitations like inability to resize the > graphs along with the widgets. That's not a big encumbrance in my case, > but the difficulty in accessing the R plot's coordinates is. The only > guidance I could find was that in James Wettenhall: > > http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/InteractiveTkrPlot.html > > but it issues an enigmatic message for the calculated coordinates: > > "Label Point Closest to These Approximate Plot Coordinates" > > Is that the best approach available, or are there better alternatives? > > My idea is to implement an integrated interface for a plotting utility I > wrote for package diveMove, which gathers pairs of coordinates from > mouse clicks (in standard unembedded graphs for now): > > ---<---------------cut here---------------start-------------->--- > install.packages("diveMove") # from any CRAN > data(divesTDR) > depth.zoc <- zoc(getTime(divesTDR), getDepth(divesTDR), offset=3) > coords <- plotTD(getTime(divesTDR), depth.zoc) > ---<---------------cut here---------------end---------------->--- > > Clicking on the "Zero-Offset Correct a Range" button, followed by a pair > of clicks in the graph, gathers coordinates using locator(). Because > users may need to zoom and pan across different scales, it is important > to allow for resizing of the plot. > > Any recommendations on how to embed R graphics on Tk widgets, and > gathering coordinates as above, would be much appreciated. Thanks. > > > Cheers, > > -- > Seb > > _______________________________________________ > R-SIG-GUI mailing list > R-SIG-GUI@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-gui > > _______________________________________________ > R-SIG-GUI mailing list > R-SIG-GUI@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-gui > -- Felix Andrews / 安福立 PhD candidate Integrated Catchment Assessment and Management Centre The Fenner School of Environment and Society The Australian National University (Building 48A), ACT 0200 Beijing Bag, Locked Bag 40, Kingston ACT 2604 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8 _______________________________________________ R-SIG-GUI mailing list R-SIG-GUI@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-gui