It seems this question has been asked a couple of times in different forms, but I could't find the right solution. I have a SpatialPoint object with several Polygons and would like to subset and plot one polygon using the slot "ID".
Using the example from this question:
Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3)
I can extract the IDs of the SpatialPolygons Object
SpP@polygons[[1]]@ID # one ID
sapply(SpP@polygons, function(x) x@ID) # all IDs
But how can I use this information to subset and plot one single polygon? Glad for any help, thanks in advance!