Created
December 14, 2023 22:52
-
-
Save walkerke/c42d03245c3d404813b6d95b0a1c5152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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