Skip to content
Prev 91266 / 398500 Next

Polygon-like interactive selection of plotted points

On Wed, 26 Apr 2006, Marc Schwartz (via MN) wrote:

            
This sequence from the splancs package should do it:

library(splancs)
set.seed(20060426)
xy <- cbind(x=runif(100), y=runif(100))
plot(xy)
poly <- getpoly() # this gets the polygon on-screen
plot(xy)
polygon(poly)
io <- inout(xy, poly) 
# this returns a logical vector for points in the polygon
points(xy[io,], pch=16, col="blue")

Roger