r - making a choropleth from SpatialPolygonsDataFrame- ggplot vs ggplot2 vs plot? -
i have shapefile, specifically, spatialpolygonsdataframe, called cdtract. contains 1 variable each district called varcount. varcount either "na" or 1. when
plot(cdtract)
...i see map printed out don't see tracts '1' in varcount marked differently 'na.' ideally want have spectrum of values in varcount , see reflected in different colors. considered using ggplot according this post here resource intensive , might better use plot() instead of ggplot() create choropleth. i'm not sure how go it. using different shapefile states/countries not sure choroplethr package way go.
can explain how take spatialpolygonsdataframe , turn choropleth, efficiently? thanks!
shamefully taken ari's post on gis.stackexchange.com. see link pictures. there more examples here.
library(sp) srs1 = polygons(list(polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))), "s1") srs2 = polygons(list(polygon(cbind(c(5,4,2,5),c(2,3,2,2)))), "s2") spdf <- spatialpolygonsdataframe( spatialpolygons(list(srs1,srs2)), data.frame(z=1:2, row.names=c("s1","s2") ) ) spplot(spdf, zcol="z")
Comments
Post a Comment