Simple feature 幾何與 tidycensus

在 R 中分析美國人口普查資料

Kyle Walker

Instructor

引數 geometry = TRUE

  • geometry = TRUE 可用於以下地理層級:
    • "state"
    • "county"
    • "tract"
    • "block group"
    • "block"
    • "zcta"(亦即 "zip code tabulation area"
在 R 中分析美國人口普查資料

取得 simple feature 幾何

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

cook_value <- get_acs(geography = "tract", state = "IL", 
                      county = "Cook", 
                      variables = "B25077_001", 
                      geometry = TRUE)
在 R 中分析美國人口普查資料

Simple feature 幾何

head(cook_value, 3)
具有 3 個要素與 5 個欄位的 simple feature 集合
geometry 類型:MULTIPOLYGON
維度:      XY
bbox:       xmin: -87.68465 ymin: 42.01232 xmax: -87.66434 ymax: 42.02297
epsg(SRID):4269
proj4string:+proj=longlat +datum=NAD83 +no_defs
        GEOID                                       NAME   variable
1 17031010100    Census Tract 101, Cook County, Illinois B25077_001
2 17031010201 Census Tract 102.01, Cook County, Illinois B25077_001
3 17031010202 Census Tract 102.02, Cook County, Illinois B25077_001
  estimate   moe                       geometry
1   230700 62332 MULTIPOLYGON (((-87.6772 42...
2   151100 19099 MULTIPOLYGON (((-87.68465 4...
3   133300 84063 MULTIPOLYGON (((-87.67685 4...
在 R 中分析美國人口普查資料

繪製 tidycensus 幾何

plot(cook_value["estimate"])

庫克郡基本圖

在 R 中分析美國人口普查資料

合併 tigris 與 tidycensus 資料

library(tigris)

idaho_income <- get_acs(geography = "school district (unified)", 
                        variables = "B19013_001", 
                        state = "ID")

idaho_school <- school_districts(state = "ID", 
                                 type = "unified", 
                                 class = "sf")

id_school_joined <- left_join(idaho_school, 
                              idaho_income, 
                              by = "GEOID")
在 R 中分析美國人口普查資料

合併 tigris 與 tidycensus 資料

plot(id_school_joined["estimate"])

愛達荷州各學區所得

在 R 中分析美國人口普查資料

移動阿拉斯加與夏威夷的幾何位置

state_value <- get_acs(geography = "state", 
                       variables = "B25077_001", 
                       survey = "acs1", 
                       geometry = TRUE, 
                       shift_geo = TRUE)

plot(state_value["estimate"])
在 R 中分析美國人口普查資料

shift_geo 繪圖

在 R 中分析美國人口普查資料

一起來練習吧!

在 R 中分析美國人口普查資料

Preparing Video For Download...