【问题标题】:Is "county subdivision" geography supported for get_acs()get_acs() 是否支持“县细分”地理
【发布时间】:2018-12-24 22:19:26
【问题描述】:

我正在尝试上传“县细分”的数据,作为 tidycensus 的 get_acs() 函数中地理选项的一部分。我知道有几个地理选项,凯尔沃克在他的页面上发布了这些选项。 https://walkerke.github.io/tidycensus/articles/basic-usage.html#geography-in-tidycensus

虽然它适用于州和县级,但您只需输入 County = "Monmouth"。但我似乎无法让语法在蒙茅斯县内的城市的城市细分级别上工作。我寻找了其他 tidycensus 脚本,但没有找到任何使用县级以下的地理。

有什么建议吗?

library(tidycensus)
library(tidyverse)
library(sf)

census_api_key("YOUR API KEY GOES HERE")

vars <- c(English = "C16002_002", 
      Spanish = "C16002_003")


language <- get_acs(geography = "county subdivision", 
                state = "NJ",
                county = "Monmouth",
                city = "Red Bank",
                table = "C16001")



rb_language <- get_acs(geography = "tract", 
                   variables = vars,
                   state = "NJ", 
                   county = "Monmouth", 
                   city = "Red Bank"
                   geometry = TRUE, 
                   summary_var = "C16002_001") %>%
  st_transform(26918)

【问题讨论】:

    标签: tidycensus


    【解决方案1】:

    我不完全清楚您是否正在尝试获取 Red Bank 县分区或人口普查区的数据 Red Bank。无论哪种情况,您都不能直接在tidycensus 中执行此操作,而是可以使用get_acs() 获取一个县的所有分区或区域,然后进一步过滤结果。

    例如,如果您只需要 Red Bank 县分区的语言数据,您可以这样做:

    library(tidycensus)
    library(tidyverse)
    library(sf)
    library(tigris)
    
    vars <- c(English = "C16002_002", 
              Spanish = "C16002_003")
    
    # get all subdivisions in monmouth county
    language_subdiv <- get_acs(geography = "county subdivision", 
                               state = "NJ",
                               county = "Monmouth",
                               table = "C16001")
    
    # only red bank borough
    language_subdiv %>% 
      filter(str_detect(NAME, "Red Bank"))
    #> # A tibble: 38 x 5
    #>    GEOID     NAME                                  variable  estimate   moe
    #>    <chr>     <chr>                                 <chr>        <dbl> <dbl>
    #>  1 34025624… Red Bank borough, Monmouth County, N… C16001_0…    11405   171
    #>  2 34025624… Red Bank borough, Monmouth County, N… C16001_0…     7227   451
    #>  3 34025624… Red Bank borough, Monmouth County, N… C16001_0…     3789   425
    #>  4 34025624… Red Bank borough, Monmouth County, N… C16001_0…     1287   247
    #>  5 34025624… Red Bank borough, Monmouth County, N… C16001_0…     2502   435
    #>  6 34025624… Red Bank borough, Monmouth County, N… C16001_0…        0    19
    #>  7 34025624… Red Bank borough, Monmouth County, N… C16001_0…        0    19
    #>  8 34025624… Red Bank borough, Monmouth County, N… C16001_0…        0    19
    #>  9 34025624… Red Bank borough, Monmouth County, N… C16001_0…       42    40
    #> 10 34025624… Red Bank borough, Monmouth County, N… C16001_0…        0    19
    #> # ... with 28 more rows
    

    现在,如果您想要 Red Bank 内的人口普查区域,您可以获取 Monmouth 的所有人口普查区域,然后使用 tigris::places() 获取 Red Bank 的边界,最后过滤人口普查区域以仅获取那些包含在其中的区域由红岸边界。

    # get all tracts in monmouth county
    language_tract <- get_acs(geography = "tract", 
                              variables = vars,
                              state = "NJ", 
                              county = "Monmouth",
                              geometry = TRUE, 
                              summary_var = "C16002_001", 
                              output = "wide")
    
    # get geometry of red bank borough 
    red_bank_place <- places("NJ", cb = TRUE, class = "sf") %>% 
      filter(NAME == "Red Bank")
    
    # only tracts in red bank borough
    red_bank_tracts <- language_tract %>% 
      filter(st_contains(red_bank_place, ., sparse = FALSE))
    
    ggplot() +
      geom_sf(data = red_bank_tracts, color = "blue", fill = NA) +
      geom_sf(data = red_bank_place, color = "black", fill = NA)
    

    reprex package (v0.2.1) 于 2018 年 12 月 24 日创建

    【讨论】:

    • 太棒了!谢谢。这就是我所了解的确切地理位置。我需要看看如何填充 ggplot,因为在我的原始代码中,我能够查看说英语和西班牙语的人的比例。看起来很酷,很好地回答了我的研究问题:)
    猜你喜欢
    • 2018-05-12
    • 2016-09-21
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多