在 ACS 中可视化误差范围

在 R 中分析美国人口普查数据

Kyle Walker

Instructor

可视化不确定性

  • 常用方法:误差线图

示例误差线图

在 R 中分析美国人口普查数据

在 ggplot2 中绘制误差范围

  • 在 ggplot2 中:geom_errorbar()geom_errorbarh()
library(tidycensus)
library(tidyverse)

wyoming_age <- get_acs(geography = "county", 
                       variables = c(medianage = "B01002_001"), 
                       state = "WY")  

ggplot(wyoming_age, aes(x = estimate, y = NAME)) + 
  geom_errorbarh(aes(xmin = estimate - moe, 
                     xmax = estimate + moe)) + 
  geom_point()
在 R 中分析美国人口普查数据

未格式化的误差范围图

在 R 中分析美国人口普查数据

格式化误差范围图

wyoming_age2 <- wyoming_age %>%
  mutate(NAME = str_replace(NAME, " County, Wyoming", ""))

ggplot(wyoming_age2, aes(x = estimate, y = reorder(NAME, estimate))) + geom_errorbarh(aes(xmin = estimate - moe, xmax = estimate + moe)) + geom_point(size = 3, color = "darkgreen") + theme_grey(base_size = 14) + labs(title = "怀俄明州各县的年龄中位数", subtitle = "2012-2016 美国社区调查", x = "ACS 估计值(条表示误差范围)", y = "")
在 R 中分析美国人口普查数据

已格式化的误差范围图

在 R 中分析美国人口普查数据

开始练习!

在 R 中分析美国人口普查数据

Preparing Video For Download...