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

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()

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 中分析美国人口普查数据