r - 如何在 R 中按邮政编码创建肯塔基地图?
问题描述
假设我有一个包含肯塔基州邮政编码和介于 -1 和 1 之间的值的数据框。我想将它们绘制为肯塔基州的热图,其中 -1 代表渐变的最低颜色,1 代表最高颜色。
我怎样才能在 R 中做到这一点?我正在使用 R Studio 1.3.959(R 版本 3.6.3)。
解决方案
An option using tigris
and sf
. Note that this uses zip code tabulation areas, which are not a 1:1 match with zip codes. Zip codes follow streets and can't be made into sensible polygons: https://gis.stackexchange.com/a/2693/162034
library(tigris)
library(sf)
# download zipcode tabulation areas and state boundaries
zcta1 <- zctas(TRUE)
sts <- states(TRUE)
# subset zipcode data
zcta_ky <- st_intersection(zcta1, sts[sts$NAME == 'Kentucky', ])
# add random 0-1 field
zcta_ky$rand <- runif(nrow(zcta_ky))
#plot
plot(zcta_ky['rand'])
推荐阅读
- reactjs - 如何在 react-data-grid 中创建自定义行渲染器
- javascript - 检查图像尺寸 - Angular 5
- android - 如何滚动由 Cordova mfilechooser 插件触发的内部存储器的文件浏览器
- apache-kafka - Auto offset commit failed for group my_group_id in kafka confluent cluster
- mysql - ORDER BY varchar 列
- java - Last known location and current location cannot be retrieved on some devices
- upload - Google Cloud Storage Signed URL PUT Content-MD5
- facebook - Facebook live_videos not authorized
- php - 如何将数据发送到 json webservice?
- python - 无法使用 Python SqlAlchemy 将数据写入 Vertica 数据库 - 类型“TEXT”不存在