Search code examples
rchoroplethr

tract_choropleth for NY data


I'm trying to replicate the map shown in Ari's ACS talk using tract_choropleth. However, the codes keep returning an Error message. I have requested the api key and other functions like state_choropleth() and county_choropleth() were working just fine.

library(choroplethr)
library(choroplethrMaps)
#api.key.install(DONE)

ny_tract = get_tract_demographics("new york", endyear = 2015)
ny_tract$value = ny_tract$per_capita_income

tract_choropleth(ny_tract, state_name="new york", title='2015 map of NY', 
legend = "dollars", num_colors = 1, county_zoom = 36061)

The Error message is

Error in maptools::unionSpatialPolygons(cp, attr[,region]): isTRUE(gpclibPermitStatus()) is not TRUE

I can see that the data frame ny_tract was loaded with many NA introduced by coercion warnings.

Thank you for your help.


Solution

  • The error is due to gpclibPermitStatus() returning FALSE.

    Unfortunately, this is a common error that comes up when working with choroplethr. I once gave a lengthy answer to the question here.

    The short answer is to type the following:

    install.packages("gpclib")
    library(maptools)
    gpclibPermit()