Jude
Jude

Reputation: 193

plot one polygon from a spatial polygon data frame

I'm a bit new to R and so this mights seem an easy command for you. I have a shapefile loaded in R with several polygons in it, and I just would like to plot the first polygon. I tried several commands but it's not working.

My aim is to crop a raster with that first element of my shapefile, again I tried several stuff but it's not working..

I hope I'm clear,

Thanks a lot!

Jude

Upvotes: 3

Views: 4850

Answers (1)

Val
Val

Reputation: 7023

Assuming your polygons are called pols, this should work for you:

plot(pols[1,])

A spatial polygon dataframe is just like any other df in this case, with each row corresponding to a feature. So if you want to subset it, you can use ordinary indexing.

Upvotes: 9

Related Questions