简体   繁体   English

如何使用 R 中的计数将 Plot 邮政编码到美国的 Map

[英]How to Plot ZipCodes onto a Map of USA using Counts in R

I am attempting to create a map of the US showing the following zipcodes and to color it based on count.我正在尝试创建一个显示以下邮政编码的美国 map 并根据计数对其进行着色。 I have tried ggmaps and chloroplethr but keep getting errors.我尝试过 ggmaps 和 chloroplethr,但不断出错。 I think I need to link the zipcodes to geocodes but have not been able to do so.我想我需要将邮政编码链接到地理编码,但无法这样做。 If anyone has any insights, much appreciated.如果有人有任何见解,非常感谢。

邮政编码和计数

You should try to provide more reproducible code.您应该尝试提供更多可重现的代码。

Here:这里:

df_count <- data.frame(zip = as.character(c(94025, 98550, 94303, 94306,
                               94062, 94305, 94301, 94061, 943125)),
                       Count = c(1465, 915, 810, 768, 715, 
                                 711, 678, 630, 584))

Then I googled for this https://catalog.data.gov/dataset/tiger-line-shapefile-2019-2010-nation-us-2010-census-5-digit-zip-code-tabulation-area-zcta5-na然后我用谷歌搜索了这个https://catalog.data.gov/dataset/tiger-line-shapefile-2019-2010-nation-us-2010-census-5-digit-zip-code-tabulation-area-zcta5-na

# Loading packages
library(sf)
library(dplyr)

# loading shapefile with zip codes
zip_codes <- sf::st_read("tl_2019_us_zcta510/tl_2019_us_zcta510.shp")

# join that only keep data in df_count
zip_with_count <- zip_codes %>%
                        dplyr::right_join(df_count, by = c("ZCTA5CE10" = "zip"))

# quick and dirty plot
plot(zip_with_count["Count"])

I will recommand that your read: https://geocompr.robinlovelace.net/index.html我建议您阅读: https://geocompr.robinlovelace.net/index.html

If you want to do better mapping check either the tmap or the cartography packages如果您想做更好的映射,请检查tmap制图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM