[R] locator() in a multiple plot setting

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Tue Jul 13 14:06:02 CEST 2004

> p <- locator(1)
> c(round(p$x), round(p$y))
> ---
> how can I get the "correct" location in the sense of a
> 3d info: (a) which slice (p$slice) (b) p$x (c) p$y

Okay, purely off the top of my head here...

You can use par()$usr, par()$plt, and par()$fig to transform from 
locator()'s coordinates to device coordinates (0,0 at one corner to 1,1 
at opposite corner). This lets you work out which of an NxM layout of 
plots you have clicked in.

  If you store par()$usr,plt,fig for each little plot then you can also 
work out the location within the plot. Its pretty much the inverse 
transform of the first computation, with an offset...

  And after much handwaving, you can work it out. And by the time I send 
this someone will have posted a full solution as an R package with 
documented functions and vignettes....


More information about the R-help mailing list