I want to find which points fall within an interest area, and then plot only those points. Here is a basic example.
Now what I want to do is plot the points that correspond to inIA's values that are greater than 0. In this example, it would be easy to plot them manually since it is the first five points (plot(1:5,1:5)), but my actual code uses points and polygons that are more complex.
For example, inIA might equal 0 0 1 0 0 1 1 1 0 1 1 and I would want to plot the third point, sixth, seventh, etc. The points are predefined in a database and numbered by order (n):
n x y
1 5 6
2 3 4
3 8 1
4 8 2
...
All the ways I tried to do this were clearly wrong, because I keep getting the message "the condition has length > 1 and only the first element will be used" when I try plotting from inIA. But I want to treat each value in inIA separately. I'm fairly new to R, so I would appreciate any help.
Code:
install.packages("sp") #install package that allows usage of point in polygon
library(sp)
x <-1:10
y <- 1:10
#polygon is plotted as (1,1) (6,1) (6,5) (1,5)
inIA <- point.in.polygon(x,y,c(1,6,6,1),c(1,1,5,5))
inIA
[1] 3 1 1 1 2 0 0 0 0 0
#inIA reports which points fall within the polygon - the first 5 points
For example, inIA might equal 0 0 1 0 0 1 1 1 0 1 1 and I would want to plot the third point, sixth, seventh, etc. The points are predefined in a database and numbered by order (n):
n x y
1 5 6
2 3 4
3 8 1
4 8 2
...
All the ways I tried to do this were clearly wrong, because I keep getting the message "the condition has length > 1 and only the first element will be used" when I try plotting from inIA. But I want to treat each value in inIA separately. I'm fairly new to R, so I would appreciate any help.