【问题标题】:R: State and County Outlines for choroplethrZipR:choroplethrZip 的州和县大纲
【发布时间】:2017-04-05 10:17:29
【问题描述】:

我有一个带有邮政编码的数据集,我使用 choroplethrZip 来绘制数据图表。我正在查看州和县级的数据。但是,邮政编码不一定与州和县线相对应。我尝试使用reference_map = TRUE,但它没有县线,并且开始看起来有点忙。有没有办法将默认参考地图更改为具有州和县线而没有其余地图详细信息的参考地图?换句话说,我不想要街道和地形。

这是我的代码,其中包含与我正在使用的数据相似的示例数据。您可以看到德克萨斯州边界的问题。

#zip.regions metadata file for choroplethrZip
data(zip.regions)
head(zip.regions)

#Test data file:A data.frame containing population estimates 
# for US Zip Code Tabulated Areas (ZCTAs) in 2012.
data(df_pop_zip) 

#Create a choropleth of US Zip Codes
zip_choropleth(df_pop_zip, 
               state_zoom="texas", 
               title="2012 Texas State ZCTA Population Estimates",
               legend="Population",
               reference_map = TRUE)

#Zoom County
dd_fips = c(48113, 48121)
zip_choropleth(df_pop_zip, 
               county_zoom=dd_fips,  
               title="2012 Denton & Dallas ZCTA Population Estimates",
               legend="Population",
               reference_map = TRUE)

TexasPlot

DentonDallasPlot

【问题讨论】:

    标签: r zipcode choropleth


    【解决方案1】:

    我使用了这个博客并了解了如何进行这项工作:http://www.arilamstein.com/blog/2015/07/02/exploring-the-demographics-of-ferguson-missouri/

    这是我的最终代码:

    library(choroplethrZip)
    library(ggplot2)
    library(choroplethr)
    
    
    #Pull in zip.regions metadata file for choroplethrZip
    data(zip.regions)
    head(zip.regions)
    
    #Test data file:A data.frame containing population estimates 
    # for US Zip Code Tabulated Areas (ZCTAs) in 2012.
    data(df_pop_zip)
    
    # highlight a county
    highlight_county = function(county_fips)
    {
      library(choroplethrMaps)
      data(county.map, package="choroplethrMaps", envir=environment())
      df = county.map[county.map$region %in% county_fips, ]
      geom_polygon(data=df, aes(long, lat, group = group), color = "yellow", fill = NA, size = 1)
    }
    
    #Zoom County
    dd_fips = c(48113, 48121)
    zip_choropleth(df_pop_zip, 
                   county_zoom=dd_fips,  
                   title="2012 Denton & Dallas ZCTA Population Estimates",
                   legend="Population",
                   reference_map = TRUE) +
                  highlight_county(dd_fips)
    

    Rplot Counties

    我只需要添加 highlight_county 函数,效果很好。当我用我的数据(而不是通用人口数据)进行测试时,它也能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多