4

I'd like to be able to generate a basic splom plot in R and then use my mouse to click on one of the sub-panels (panel.pairs, specifically) and have R return either the coordinates of that sub-panel, or even better, the names of the corresponding variables plotted in that sub-panel.

Here's an example splom to work with:

require(lattice)
data(iris)
super.sym <- trellis.par.get("superpose.symbol")
splom(~iris[1:4], groups = Species, data = iris,
      panel = panel.superpose,
      key = list(title = "Three Varieties of Iris",
                 columns = 3, 
                 points = list(pch = super.sym$pch[1:3],
                               col = super.sym$col[1:3]),
                 text = list(c("Setosa", "Versicolor", "Virginica"))))

Here's the closest I've gotten so far, which lets me click on a point in one of the sub-panels, and observe where that point appears elsewhere. Not actually what I want, but it leads me to believe it's possible:

trellis.focus()
panel.link.splom()

trellis.unfocus() #to close the trellis.focus session
GSee
  • 48,880
  • 13
  • 125
  • 145
theEricStone
  • 301
  • 1
  • 7
  • Good question. Could you please edit the two lines beginning `points = list(...`? `super.sym` is not defined, so the example isn't reproducible as it stands (though it's close). Thanks. – Josh O'Brien Dec 11 '12 at 16:29
  • sorry about that, seems you figured out it's just from the `?splom` help. thanks for fixing! – theEricStone Dec 12 '12 at 15:50

2 Answers2

1

You can use option verbose to get details :

 panel.link.splom(verbose=TRUE)

you get in the console :

Click to choose one point to highlight
    Sepal.Length Sepal.Width Petal.Length Petal.Width
141          6.7         3.1          5.6         2.4

One can imagine this scenario:

  1. You can then redirect the console with sink

    con <- file("pointsselected.log")
    sink(con, append=TRUE)
    
  2. Selects some points in the plot.

  3. select a point not on the panel( exterior to the plot)

  4. restore the console

    sink() 
    
  5. read all points selected

       cat(readLines("pointsselected.log"), sep="\n")
    

But from the help , the interactive options are still experimental and the exact details may change in future.

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • I can't quite get this to work, maybe I'm doing something in the wrong order? First, make the splom, next enter trellis.focus(), then panel.link.splom(verbose=TRUE), then follow your steps 1 - 4? R says this: Warning message: closing unused connection 4 (pointsselected.log) – theEricStone Dec 11 '12 at 19:58
  • @theEricStone I update a little bit my answer but you are doing in the good order.. – agstudy Dec 11 '12 at 20:19
0

This is very close to what I'm looking for, posted to the R Help list yesterday: http://r.789695.n4.nabble.com/Focus-on-a-sub-panel-of-a-splom-with-trellis-focs-return-coordinate-of-sub-panel-or-names-of-variabln-td4652825.html

1) Construct same splom() as above.

2) Make sure you have run library(grid)

3) Now run these lines:

trellis.focus()
names(iris)[round(unlist(grid.locator()))]

4) Click on any portion of the plot and then end the focus session:

trellis.unfocus() 

I say this is very close in that it does precisely what I want, but I want the capture of names(.)[.] to remain open even after a click. Any thoughts?

theEricStone
  • 301
  • 1
  • 7