Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created January 8, 2022 20:58
Show Gist options
  • Save walkerke/131f9cb2d35967c5f376a0001a9686c1 to your computer and use it in GitHub Desktop.
Save walkerke/131f9cb2d35967c5f376a0001a9686c1 to your computer and use it in GitHub Desktop.
library(tidycensus)
library(tidyverse)
dc_density <- get_acs(
geography = "tract",
state = "DC",
variables = "B01003_001",
geometry = TRUE,
keep_geo_vars = TRUE
) %>%
mutate(density_km2 = estimate / (ALAND / 1000000))
ggplot(dc_density) +
geom_sf(aes(fill = density_km2)) +
theme_void() +
scale_fill_viridis_c() +
labs(
title = "Population density in Washington, DC",
fill = "Pop/km2"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment