使用 ggplot2 視覺化 Census 資料

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

Kyle Walker

Instructor

ggplot2:R 中的分層圖形文法

ggplot2 六角標誌

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

範例:各州收入視覺化

library(tidycensus)
library(tidyverse)

ne_income <- get_acs(geography = "state", 
                     variables = "B19013_001", 
                     survey = "acs1", 
                     state = c("ME", "NH", "VT", "MA", 
                               "RI", "CT", "NY"))

ggplot(ne_income, aes(x = estimate, y = NAME)) + geom_point()
在 R 中分析美國人口普查資料

未排版的點圖

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

自訂 ACS 資料的 ggplot2 圖形

ggplot(ne_income, 
       aes(x = estimate, 
           y = reorder(NAME, estimate))) + 
  geom_point(color = "navy", size = 4) +

scale_x_continuous(labels = scales::dollar) +
theme_minimal(base_size = 14) +
labs(x = "2016 ACS estimate", y = "", title = "Median household income by state")
在 R 中分析美國人口普查資料

已排版的點圖

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

一起來練習吧!

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

Preparing Video For Download...