[R] determining plot location in lattice

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri Nov 7 20:42:47 CET 2008


Hi,

I'm dealing with a lattice plot inserted into a tk widget and would like 
to know when a user has clicked on the plot area of a plot (i.e. inside 
the axes). For example,

library(tkrplot)
library(lattice)
tt <- tktoplevel()
makePlot <- function() print(xyplot(1 ~ 1))
printCoords <- function(x, y) print(c(x, y))
img <- tkrplot(tt, makePlot)
tkbind(img, "<1>", printCoords)
tkpack(img)

I would like to know when a user clicks inside the axes, but don't know 
how to determine where the plot region is. Essentially, this comes down 
to answering the following question: Assuming the entire plot is on a 
unit square, what are the coordinates of the plotting area?

This question is may seem unrelated to tkrplot, but outside of this 
context I may not get answers that work. I have been playing with both 
lattice::trellis.focus and grid::grid.locator to no avail.

Thanks,

--sundar



More information about the R-help mailing list