The goal of donnermap
is to quickly plot data visualizations involving
states and congressional districts.
It uses the Daily Kos Election (http://dkel.ec/map) 2.0 Congressional District Map, where districts are drawn roughly proportional to the number of seats they have in the US Congress. This is beneficial for some visualizations where traditional maps will obscure densely populated areas such as New York City, Los Angeles, Miami, and Houston.
The package is named after Daniel Donner, who made this map. A discussion of the map can be found here.
The development version can be installed from this repository with:
# install.packages("devtools")
devtools::install_github("kuriwaki/donner-map")
library(donnermap)
# For graphing
library(ggplot2)
library(sf)
library(ggthemes)
library(dplyr)
library(scales)
The objects cd_shp
(and st_shp
, for states) is a sf
-class R object
that includes the Daily Kos Elections cartogram as its geometry. It can
be easily plotted with geom_sf()
.
ggplot(cd_shp) + geom_sf() + theme_map() +
labs(caption = "Map Source: http://dkel.ec/map")
Joining a shape file to a dataframe (but not the reverse) will append the data. Since the race data here is in long form, the joined dataframe will be in long-form as well.
cd_race <- left_join(cd_shp, race_by_cd, by = "cd")
# plot
ggplot(cd_race) +
geom_sf(data = st_shp, fill = "transparent", size = 0.5) +
geom_sf(aes(fill = frac), size = 0.1, color = "white") +
scale_fill_viridis_b(
"Percent of Voting Age",
na.value = "white",
breaks = seq(0, 1, 0.1),
labels = percent_format(accuracy = 1)) +
facet_wrap(~ race) +
theme_map() +
labs(caption = "Map Source: http://dkel.ec/map. Race Data: ACS 2014-2018, obtained through Kyle Walker's tidycensus.") +
theme(legend.position = c(0.75, 0.1))