Created
April 30, 2021 20:20
-
-
Save walkerke/7c392beac25d3c955f8dcd4d66aedf26 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(tigris) | |
library(ggiraph) | |
library(tidyverse) | |
us_median_age <- get_acs( | |
geography = "state", | |
variables = "B01002_001", | |
year = 2019, | |
survey = "acs5", | |
geometry = TRUE, | |
resolution = "20m" | |
) %>% | |
shift_geometry() %>% | |
mutate(tooltip = paste(NAME, estimate, sep = ": ")) | |
gg <- ggplot(us_median_age) + | |
geom_sf_interactive(aes(fill = estimate, | |
tooltip = tooltip, | |
data_id = NAME), | |
size = 0.3) + | |
scale_fill_distiller(palette = "RdPu", | |
direction = 1) + | |
labs(title = "Median Age by State, 2019", | |
caption = "Data source: 2019 1-year ACS, US Census Bureau", | |
fill = "ACS estimate") + | |
theme_void() | |
girafe(ggobj = gg) %>% | |
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