Re: [Rd] Getting the panel location of a xyplot matrix using a mouse click in a GDCanvas

From: Deepayan Sarkar <>
Date: Thu, 23 Oct 2008 12:55:08 -0700

On Thu, Oct 23, 2008 at 12:26 PM, Daniel Kornhauser <> wrote:
> Hi:
> I would like to find out the panel of a xyplot matrix where a mouse clicked.
> I know this functionality is already bundled in trellis.focus but I can't
> use it because I am coding a stand alone application in Java using with
> GDCanvas as a graphics device.
> I tried calling trellis.focus from Java with:
> re.eval("t = trellis.focus()"));
> However it did not work for an embedded GDCanvas. The above call to the
> trellis.focus() returns null no matter where I click.
> (Side note: the functionality must be implemented in the GDCanvas because
> trellis.focus does work correctly in JGR)
> I wish to handle all the user GUI events in Java to evaluate different
> commands in an Rengine.
> With a GDCanvas, it's straightforward to get the x y position of a mouse
> click with the standard e.getX() and e.getY()
> So my handler would look like:
> public void mouseClicked(MouseEvent e) {
> System.out.println("Clicked" + e.getX() + " " + e.getY());
> System.out.println(re.eval("t = trellis.focus()"));
> System.out.println(re.eval("t"));
> // I would update the panel here ...
> }
> I am only using Java because:
> - I am proficient in Java GUI programmer
> - It is multiplatform
> Another way of posing the question is:
> Given the coordinates from grid.location how can I find out the plane of an
> xyplot matrix where the user clicked.
> I have tried to figure out how to do it from code using trellis.clickFocus,
> but I have have only been playing with R for a week, so I am quite lost
> reading R code.

The approach in trellis.clickFocus should get you close. One important point is that

clickLoc <- grid.locator("npc")

returns the location in NPC, whereas your e.getX() and e.getY() would be in device coordinates. help(grconvertX) should tell you how to make the conversion.

-Deepayan mailing list Received on Thu 23 Oct 2008 - 19:57:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 24 Oct 2008 - 21:30:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive