Skip to content

Instantly share code, notes, and snippets.

@walkerke
Created November 18, 2022 14:51
Show Gist options
  • Save walkerke/c94b85383e0e333007bb7af77b1c44b9 to your computer and use it in GitHub Desktop.
Save walkerke/c94b85383e0e333007bb7af77b1c44b9 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()
blue_counties <- counties(cb = TRUE, resolution = "20m") %>%
filter(str_detect(NAME, "Blue|Azul|Bleu")) %>%
shift_geometry()
blue_places <- places(cb = TRUE) %>%
filter(str_detect(NAME, "Blue|Azul|Bleu"),
STATEFP != "78") %>%
st_centroid() %>%
shift_geometry()
ggplot() +
with_shadow(
geom_sf(data = state_borders, fill = "grey80", color = "grey20"),
colour = "blue", x_offset = -3, y_offset = 3
) +
with_shadow(
geom_sf(data = blue_counties, fill = "blue", color = "white"),
colour = "white", x_offset = -1, y_offset = 1
) +
geom_sf(data = blue_places, color = "white", alpha = 0.75,
fill = "blue", shape = 21) +
theme_void(base_size = 16, base_family = "Roboto") +
labs(title = "I've got the (shapefile) blues",
subtitle = "U.S. counties & cities with 'Blue' in their names",
caption = "@kyle_e_walker | tigris R package") +
theme(plot.margin = margin(0, 0.1, 0, 0, "cm"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment