簡體   English   中英

如何使用 R 中的計數將 Plot 郵政編碼到美國的 Map

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

我正在嘗試創建一個顯示以下郵政編碼的美國 map 並根據計數對其進行着色。 我嘗試過 ggmaps 和 chloroplethr,但不斷出錯。 我想我需要將郵政編碼鏈接到地理編碼,但無法這樣做。 如果有人有任何見解,非常感謝。

郵政編碼和計數

您應該嘗試提供更多可重現的代碼。

這里:

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))

然后我用谷歌搜索了這個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"])

我建議您閱讀: https://geocompr.robinlovelace.net/index.html

如果您想做更好的映射,請檢查tmap制圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM