合併 tigris 與 tidycensus 的資料
目前,tidycensus 對核心 Census 階層中的地理單位(州、郡、Census tract、block group、block)以及郵遞區統計區(zip code tabulation areas)提供幾何資料支援。不過,你也許會想要繪製其他地理單位的資料。這種情況下,你可以使用 tigris 套件從 Census Bureau 下載對應的邊界檔,然後將你的人口統計資料與其連接,用於製圖。
本練習屬於課程
在 R 中分析美國人口普查資料
練習說明
- 使用地理識別
"school district (unified)"來取得 Idaho 各統一學區(unified school district)的家庭收入中位數。 - 使用
school_districts()取得 Idaho 的統一學區邊界。 - 使用
left_join()將兩個資料集合併在一起。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get an income dataset for Idaho by school district
idaho_income <- ___(___ = ___,
variables = "B19013_001",
___ = "ID")
# Get a school district dataset for Idaho
idaho_school <- ___(state = "ID", type = "unified", class = "sf")
# Join the income dataset to the boundaries dataset
id_school_joined <- ___(idaho_school, ___, ___ = "GEOID")
plot(id_school_joined["estimate"])