Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created November 6, 2018 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheiss/a0114af7d9475ba149bafe4b7973ebf8 to your computer and use it in GitHub Desktop.
Save andrewheiss/a0114af7d9475ba149bafe4b7973ebf8 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(sf)
library(scico)
# https://gis.utah.gov/data/boundaries/citycountystate/
counties <- st_read("data/Counties/Counties.shp")
# https://gis.utah.gov/data/society/schools-libraries/
libraries <- st_read("data/Libraries/Libraries.shp")
# Count the number of libraries per county
libraries_county <- libraries %>%
group_by(COUNTY) %>%
summarize(num_libraries = n()) %>%
# Make NAME uppercase for joining later
mutate(NAME = str_to_upper(COUNTY))
# Merge the county-level library counts with the county data
counties_with_data <- counties %>%
st_join(libraries_county) %>%
mutate(people_per_library = POP_CURRES / num_libraries)
# Plot this!
ggplot() +
geom_sf(data = counties_with_data, aes(fill = people_per_library), size = 0.25) +
geom_sf(data = libraries, size = 0.5) +
coord_sf(crs = 26912, datum = NA) +
scale_fill_scico(palette = "bilbao", end = 0.9,
labels = scales::comma, na.value = "white",
name = "People per library") +
guides(fill = guide_colorbar(barwidth = 10, barheight = 1)) +
labs(title = "Libraries in Utah",
subtitle = "Davis and Weber counties seem to be the most\nunderserved given their populations") +
theme_void(base_family = "Clear Sans") +
theme(legend.position = "bottom",
plot.title = element_text(face = "bold"))
@andrewheiss
Copy link
Author

Here's the final map

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment