【问题标题】:How to Plot ZipCodes onto a Map of USA using Counts in R [closed]如何使用 R 中的计数将邮政编码绘制到美国地图上 [关闭]
【发布时间】:2021-12-31 20:54:09
【问题描述】:

我正在尝试创建显示以下邮政编码的美国地图并根据计数对其进行着色。我尝试过 ggmaps 和 chloroplethr,但不断出错。我想我需要将邮政编码链接到地理编码,但无法这样做。如果有人有任何见解,不胜感激。

【问题讨论】:

    标签: r


    【解决方案1】:

    您应该尝试提供更多可重现的代码。

    这里:

    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-u-s-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

    如果您想进行更好的映射,请检查 tmapcartography

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 2017-01-27
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      相关资源
      最近更新 更多