[R-gui] embedding R graphics in Tk widgets

Sebastian P. Luque spluque at gmail.com
Fri Jun 13 05:13:55 CEST 2008


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



More information about the R-SIG-GUI mailing list