Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created December 14, 2023 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkerke/c42d03245c3d404813b6d95b0a1c5152 to your computer and use it in GitHub Desktop.
Save walkerke/c42d03245c3d404813b6d95b0a1c5152 to your computer and use it in GitHub Desktop.
library(tidycensus)
library(tidyverse)
library(ggridges)
library(showtext)
font_add_google("Montserrat")
showtext_auto()
all_tract_incomes <- get_acs(
geography = "tract",
variables = "B19013_001",
state = c(state.abb, "DC"),
year = 2022
) %>%
separate(NAME, into = c("tract", "county", "state"),
sep = ";") %>%
group_by(state) %>%
mutate(median = median(estimate, na.rm = TRUE)) %>%
ungroup()
ggplot(all_tract_incomes, aes(x = estimate, y = reorder(state, median),
fill = after_stat(x))) +
geom_density_ridges_gradient() +
theme_ridges(font_size = 10, font_family = "Montserrat") +
scale_fill_viridis_c(option = "inferno", guide = "none") +
labs(x = "Distribution of tract median household incomes by state\n2018-2022 ACS estimates | tidycensus R package",
y = "") +
scale_x_continuous(labels = scales::label_dollar()) +
theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment