Created
November 15, 2021 15:27
-
-
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")
This file contains hidden or 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(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