Question

I am plotting a xyplot with Lattice within R-Studio's plot window on a Mac. In addition I am interested in Lattice's interactive feature panel.identify to get a label for a data point clicked with the mouse.

library(lattice)

df= mtcars

xyplot(mpg ~ disp | as.factor(gear), 
       data= df,
       layout = c(1, 3),
       type= c("p", "g"), 
       subscripts= TRUE)

while (!is.null(fp <- trellis.focus(clip.off=F))) {
  if (fp$col > 0 & fp$row > 0)
  panel.identify(labels = df$qsec)
} 

Problem: I get the Lattice plot done but the panel.identify function does not work properly: Switching from one panel to the other is not recognized. So once I have chosen a specific panel first, the panel.identify function just recognized clicking on data only on the very panel.

Question: - Any ideas how to improve the code ?
- Is R-Studio limited to handle the panel.identify function within it's own plot window ?

Was it helpful?

Solution

I just learned myself, that the behavior described in the question is actually the regular intended one.

Solution to switch panels:

You can switch the panel by hitting ESC once, then you can bring the focus to another panel by clicking on it. Once you have the focus on the new panel, panel.identify will allow to select new data. Be careful to switch ESC twice, because then the whole identify loop will be escaped.

This works also in R-Studio.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top