首页 > 解决方案 > 纽约数据的 tract_choropleth

问题描述

我正在尝试使用 tract_choropleth复制 Ari 的ACS 演讲中显示的地图。但是,代码不断返回错误消息。我已请求 api 密钥和 state_choropleth() 和 County_choropleth() 等其他功能工作得很好。

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)

错误消息是

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

我可以看到数据框 ny_tract 加载了许多由强制警告引入的 NA。

谢谢您的帮助。

标签: rchoroplethr

解决方案


该错误是由于gpclibPermitStatus()返回 FALSE。

不幸的是,这是使用 choroplethr 时出现的常见错误。我曾经在这里对这个问题给出了一个冗长的回答。

简短的回答是输入以下内容:

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

推荐阅读