Skip to content

Instantly share code, notes, and snippets.

@mikemahoney218
Created November 15, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemahoney218/ce91f4f752e50abdb407f5a87ba522a1 to your computer and use it in GitHub Desktop.
Save mikemahoney218/ce91f4f752e50abdb407f5a87ba522a1 to your computer and use it in GitHub Desktop.
Code for my map for the 2021 30 Day Map Challenge day 15 ("Population")
library(sf)
library(tidycensus)
library(ggplot2)
library(dplyr)
acs_pop <- lapply(
setdiff(state.abb, c("AK", "HI")),
\(x) {
get_acs(
geography = "block group",
variables = "B01003_001",
state = x,
year = 2019,
geometry = TRUE
)
}
)
acs_pop <- acs_pop %>%
do.call(rbind, .)
acs_centroid <- st_centroid(acs_pop)
acs_centroid$quantity <- ceiling(acs_centroid$estimate / 1000)
acs_centroid <- acs_centroid |>
as_tibble() |>
tidyr::uncount(quantity) |>
st_as_sf()
ggplot(acs_centroid) +
geom_sf(alpha = 0.08, color = "yellow", size = 0.001) +
theme_void() +
theme(plot.background = element_rect(fill = "#111111", color = NA))
ggsave("20211116.png", width = 17, height = 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment