Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created November 4, 2022 13:45
Show Gist options
  • Save walkerke/8a6c5e9894de1dc40725c8fd389fad6c to your computer and use it in GitHub Desktop.
Save walkerke/8a6c5e9894de1dc40725c8fd389fad6c to your computer and use it in GitHub Desktop.
library(tigris)
library(tidyverse)
library(showtext)
library(sf)
library(ggfx)
options(tigris_use_cache = TRUE)
font_add_google("Roboto", "Roboto")
showtext_auto()
state_borders <- states(cb = TRUE, resolution = "20m") %>%
shift_geometry()
green_counties <- counties(cb = TRUE, resolution = "20m") %>%
filter(str_detect(NAME, "Green|Verde")) %>%
shift_geometry()
green_places <- places(cb = TRUE) %>%
filter(str_detect(NAME, "Green|Verde")) %>%
st_centroid() %>%
shift_geometry()
ggplot() +
with_shadow(
geom_sf(data = state_borders, fill = "grey80", color = "grey20"),
colour = "darkgreen", x_offset = -3, y_offset = 3
) +
with_shadow(
geom_sf(data = green_counties, fill = "darkgreen", color = "white"),
colour = "white", x_offset = -1, y_offset = 1
) +
geom_sf(data = green_places, color = "white", alpha = 0.75,
fill = "darkgreen", shape = 21) +
theme_void(base_size = 16, base_family = "Roboto") +
labs(title = "U.S. counties & cities with 'Green' or 'Verde' in their name",
subtitle = "Source: Census cartographic boundary shapefiles",
caption = "@kyle_e_walker | tigris R package")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment