Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created May 26, 2021 12:29
Show Gist options
  • Save walkerke/3628171efae66421c299c9f2dbee0f34 to your computer and use it in GitHub Desktop.
Save walkerke/3628171efae66421c299c9f2dbee0f34 to your computer and use it in GitHub Desktop.
library(tidycensus)
library(ggiraph)
library(tidyverse)
library(patchwork)
vt_income <- get_acs(
geography = "county",
variables = "B19013_001",
state = "VT",
year = 2019,
geometry = TRUE
) %>%
mutate(NAME = str_remove(NAME, " County, Vermont"))
vt_map <- ggplot(vt_income, aes(fill = estimate)) +
geom_sf_interactive(aes(data_id = GEOID)) +
scale_fill_distiller(palette = "Greens",
direction = 1,
guide = FALSE) +
theme_void()
vt_plot <- ggplot(vt_income, aes(x = estimate, y = reorder(NAME, estimate),
fill = estimate)) +
geom_errorbarh(aes(xmin = estimate - moe, xmax = estimate + moe)) +
geom_point_interactive(color = "black", size = 4, shape = 21,
aes(data_id = GEOID)) +
scale_fill_distiller(palette = "Greens", direction = 1,
labels = scales::dollar) +
labs(title = "Household income by county in Vermont",
subtitle = "2015-2019 American Community Survey",
y = "",
x = "ACS estimate (bars represent margin of error)",
fill = "ACS estimate") +
theme_minimal()
girafe(ggobj = vt_map + vt_plot, width_svg = 10, height_svg = 4) %>%
girafe_options(opts_hover(css = "fill:cyan;"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment