%inside% | R Documentation |
Check if points lie inside a simple polygon
points %inside% polygon
points |
a data.frame with components x,y specifying the points |
polygon |
a data.frame with components x,y specifying the polygon |
a logical value matching the number of points, TRUE = "inside"
oldPar <- par(pty = "s", las = 1, xpd = NA) pts <- expand.grid(x = seq(0, 1, len=25), y = seq(0, 1, len=25)) pol <- (1 + 1i)/2 + complex(argument = seq(-base::pi, base::pi, len=100))/3 show_red <- as_points(pts) %inside% as_polygon(pol) plot(pts, col = ifelse(show_red, "red", "royal blue"), ann = FALSE, bty = "n", pch = ".", cex = ifelse(show_red, 4, 2.5), asp = 1) polygon(pol, lwd = 0.5) par(oldPar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.