Roc Sc Roc Sc - 4 months ago 24
R Question

R: Free hand selection of data points in scatter plots

I would like to know if there is any good way to allow me getting the id of the points from a scatter plot by drawing a free hand polygon in R?
I found scatterD3 and it looks nice, but I can't manage to output the lab to a variable in R.
Thank you.

Roc

Answer

Here's one way

library(iplots)
with(iris, iplot(Sepal.Width,Petal.Width))

Use SHIFT (xor) or SHIFT+ALT (and) to select points (red):

enter image description here

Then:

iris[iset.selected(), ]
#     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
# 119          7.7         2.6          6.9         2.3 virginica
# 115          5.8         2.8          5.1         2.4 virginica
# 133          6.4         2.8          5.6         2.2 virginica
# 136          7.7         3.0          6.1         2.3 virginica
# 146          6.7         3.0          5.2         2.3 virginica
# 142          6.9         3.1          5.1         2.3 virginica

gives you the selected rows.