Last active
November 10, 2020 23:16
-
-
Save kylebutts/d6fe595e52d6a7a1a5fa8bd850295555 to your computer and use it in GitHub Desktop.
This file contains 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(tidyverse) | |
library(sf) | |
library(tigris) | |
library(rmapshaper) | |
source("https://gist.githubusercontent.com/kylebutts/7dc66a01ec7e499faa90b4f1fd46ef9f/raw/15196997e5aad41696b03c49be3bfaaca132fdf2/theme_kyle.R") | |
counties <- tigris::counties(class = "sf") %>% | |
# Continental | |
filter(!(STATEFP %in% c("02", "15", "60", "66", "69", "72", "78"))) %>% | |
# Simplifies details to make plotting quicker | |
rmapshaper::ms_simplify(keep = 0.01) %>% | |
# Use a good projection | |
st_transform(st_crs(2163)) %>% | |
# Random variable for plotting | |
mutate(var = runif(n())) | |
states <- counties %>% group_by(STATEFP) %>% summarize() | |
us <- counties %>% summarize() | |
ggplot() + | |
geom_sf(data = counties, aes(fill = var), | |
color = "grey", size = 0.2) + | |
geom_sf(data = us, color = "black", fill = NA) + | |
# geom_sf(data = states, color = "black", fill = NA) + | |
# No lat-long | |
coord_sf(datum = NA)+ | |
theme_kyle() + | |
# Continuous Scale | |
scale_fill_distiller(palette = "RdBu") | |
# Discrete Scale | |
# scale_fill_brewer() | |
Author
kylebutts
commented
Nov 10, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment