Skip to content

Instantly share code, notes, and snippets.

@clauswilke
Created July 5, 2018 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clauswilke/5dfdff4df2072d4785b8ed9d87ae8a85 to your computer and use it in GitHub Desktop.
Save clauswilke/5dfdff4df2072d4785b8ed9d87ae8a85 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(multiscales)
colors <- scales::colour_ramp(
colors = c(red = "#AC202F", purple = "#740280", blue = "#2265A3")
)((0:7)/7)
types <- c(
'Natural state geometry',
'Cartogram weigted by electoral votes'
)
US_polling$type <- types[1]
US_polling_cartogram$type <- types[2]
US_all <- rbind(US_polling, US_polling_cartogram)
US_all$type <- factor(US_all$type, levels = types)
ggplot(US_all) +
geom_sf(aes(fill = zip(Clinton_lead, moe_normalized)), color = "gray30", size = 0.2) +
coord_sf(datum = NA) +
bivariate_scale(
"fill",
pal_vsup(values = colors, max_desat = 0.8, pow_desat = 0.2, max_light = 0.7, pow_light = 1),
name = c("Clinton lead", "uncertainty"),
limits = list(c(-40, 40), c(0, 1)),
breaks = list(c(-40, -20, 0, 20, 40), c(0, 0.25, 0.50, 0.75, 1.)),
labels = list(waiver(), scales::percent),
guide = "colourfan"
) +
theme_void() +
theme(
strip.text = element_text(size = 11, margin = margin(3, 0, 3, 0)),
legend.key.size = grid::unit(0.8, "cm"),
legend.title.align = 0.5,
plot.margin = margin(5.5, 20, 5.5, 5.5)
) +
facet_wrap(~type, ncol = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment