The data was furnished courtesy of the Annie E. Casey Kids County initiative. Low birth weight is an excellent indicator of overall maternal and infant health. My home county--Henderson County, Kentucky--has struggled in this area for years. This project was undertaken to learn about leaflet choropleth maps and had the benefit of a working model on the "Kids Count" website. (The website allows for a county choropleth map to be drawn using one of dozens of indicators.)
Efforts to join the dataframe with the shapefile were challenging. When performing the operation, an error message was generated that row.names
did not match polygon ID
. Several different methods were attempted including the one below:
#crucial insight came from Robin Lovelace
# dplyr::left_join function
lnd@data <- left_join(lnd@data, crime_ag, by = c('name' = 'Borough'))
GIS exchange had a question that directly addressed the issue. The author noted that matching rownames with polygon id was a common problem. This GIS exchange post gave the background to the problem and most most importantly showed how to get the polygon ID from the polyspatial object. I was finally able to get it to work.
#assign polygon id to column variable in
#county line .shp file
cl.01@data$pid <- sapply(slot(cl.01, "polygons"), function(x) slot(x, "ID"))
Distributed under the MIT License. See LICENSE
for more information.
Rob Wiederstein - @https://twitter.com/RobWiederstein - rob@robwiederstein.org
Project Link: https://github.com/RobWiederstein/ky_lbw
Annie E. Casey Kids County Initiative.
Kentucky Open GIS Data Portal.
Robin Lovelace--Creating Maps in R.
Robin Lovelace--Geocomputation in R.