Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Last active December 20, 2021 13:11
Show Gist options
  • Save charliejhadley/f4c6cdbfc69c4d10dce504da5e194c69 to your computer and use it in GitHub Desktop.
Save charliejhadley/f4c6cdbfc69c4d10dce504da5e194c69 to your computer and use it in GitHub Desktop.
library(tigris)
library(sf)
library(rmapshaper)
library(tidyverse)
library(readxl)
library(janitor)
library(mapview)
library(tidycensus)
us_states <- states() %>%
clean_names() %>%
mutate(statefp = as.numeric(statefp))
south_atlantic_states <- us_states %>%
filter(division == 5) %>%
ms_simplify()
prisoners_per_state <- get_decennial(geography = "state",
variables = c("state_prison_population" = "PCT020006")) %>%
clean_names() %>%
mutate(state_prison_population = if_else(name == "District of Columbia",
NA_real_,
value))
south_atlantic_prisons <- south_atlantic_states %>%
left_join(prisoners_per_state)
# ==== Your turn =====
south_atlantic_prisons %>%
ggplot() +
geom_sf(aes(fill = state_prison_population,
shape = "District of Columbia"),
size = 0.1,
color = "white") +
scale_fill_viridis_c(na.value = "pink") +
guides(shape = guide_legend(override.aes = list(fill = "pink",
color = "transparent"),
title = NULL,
order = 2),
fill = guide_colorbar(order = 1)) +
theme_void()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment