문제

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 ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top