I am using the PBSmapping package in R to model data from diva-gis. I can read in the shapefiles and plot them with no issue.
library(PBSmapping)
df = importShapefile("/path/df.shp")
plotPolys(df)
But the problem is I can't figure out how to subset the PolySet data. For example, for Bhutan's administrative areas file, runnning str(df) shows:
Classes ‘PolySet’ and 'data.frame': 59294 obs. of 5 variables:
$ PID: int 1 1 1 1 1 1 1 1 1 1 ...
$ SID: int 1 1 1 1 1 1 1 1 1 1 ...
$ POS: int 1 2 3 4 5 6 7 8 9 10 ...
$ X : num 91 91 91 91 91 ...
$ Y : num 27.2 27.2 27.2 27.2 27.2 ...
- attr(*, "PolyData")=Classes ‘PolyData’ and 'data.frame': 201 obs. of 19 variables:
..$ PID : int 1 2 3 4 5 6 7 8 9 10 ...
..$ ID_0 : int 35 35 35 35 35 35 35 35 35 35 ...
..$ ISO : Factor w/ 1 level "BTN": 1 1 1 1 1 1 1 1 1 1 ...
..$ NAME_0 : Factor w/ 1 level "Bhutan": 1 1 1 1 1 1 1 1 1 1 ...
..$ ID_1 : int 486 486 486 486 486 486 486 486 472 472 ...
..$ NAME_1 : Factor w/ 20 levels "Bumthang","Chhukha",..: 15 15 15 15 15 15 15 15 1 1 ...
..$ ID_2 : int 9280 9281 9282 9283 9284 9285 9286 9287 9141 9142 ...
..$ NAME_2 : Factor w/ 201 levels "Aemeri","Athang",..: 8 19 73 126 129 138 163 186 4 29 ...
..$ VARNAME_2 : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
..$ NL_NAME_2 : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
..$ HASC_2 : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
..$ CC_2 : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
..$ TYPE_2 : Factor w/ 1 level "Unknown": 1 1 1 1 1 1 1 1 1 1 ...
..$ ENGTYPE_2 : Factor w/ 1 level "Unknown": 1 1 1 1 1 1 1 1 1 1 ...
..$ VALIDFR_2 : Factor w/ 1 level "Unknown": 1 1 1 1 1 1 1 1 1 1 ...
..$ VALIDTO_2 : Factor w/ 1 level "Unknown": 1 1 1 1 1 1 1 1 1 1 ...
..$ REMARKS_2 : Factor w/ 1 level "Second level is probably 3rd level": 1 1 1 1 1 1 1 1 1 1 ...
..$ Shape_Leng: num 0.82 0.706 0.433 1.053 0.751 ...
..$ Shape_Area: num 0.01852 0.01736 0.00877 0.04298 0.01871 ...
- attr(*, "parent.child")= num 1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "shpType")= int 5
- attr(*, "prj")= chr "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"D"| __truncated__
- attr(*, "projection")= chr "LL"
How can I subset out PolySet data where "Name_1" is "Bumthang"? Incidentally, in maptools, this can be done by:
library(maptools)
df = readShapeSpatial("/path/df.shp")
df.data = as.data.frame(df) #For understanding the data structure
df.Bumthang = admin.mpt[as.character(admin.mpt$NAME_1)=='Bumthang',]


