Last active
April 26, 2022 15:09
-
-
Save CnrLwlss/c3ee2ddf7a06e0f843d6760a5401578f to your computer and use it in GitHub Desktop.
Interactive selection of points in a scatterplot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
xvals = rnorm(1000) | |
yvals = rnorm(1000) | |
alpha = 0.1 | |
# Note you need to terminate by right-clicking and selecting "stop" | |
plot(xvals,yvals,xlab="x",ylab="y",pch=16,col=rgb(1,0,0,alpha)) | |
res = locator(n=4000, type="o") | |
selected = point.in.polygon(xvals,yvals,res$x,res$y)==1 | |
plot(NULL,xlim=range(xvals),ylim=range(yvals),xlab="x",ylab="y") | |
points(xvals[selected],yvals[selected],pch=16,col=rgb(0,0,1,alpha)) | |
points(xvals[!selected],yvals[!selected],pch=16,col=rgb(1,0,0,alpha)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment