library(tidyverse)
library(usdata)
library(sjPlot)
library(gtsummary)
gerrymander <- usdata::gerrymanderAE03 - Exploring gerrymandring
Using data to investigate patterns
Need a refresher on a plot type? Math 130’s plot reference guide is a good place to look.
Purpose
Gerrymandering is when a district’s boundaries are drawn to favor one political party (e.g. packing opposing voters into one district, or splitting them across several so they can’t win any). Lets explore some data on the 2016 election and outcomes related to the votes and gerrymandering.
- Translate English questions into code, using the data dictionary to find variable names
- Revisit and adapt code you’ve already written
- Back up every answer with specifics from your visualization — code alone isn’t an answer
Note that there are many ways to answer these questions. Some functions are suggested for you to use. You can choose your own adventure, but 1) you must use functions we have taught in this class so far, and 2) you should compare to your neighbor to make sure you are getting the same numbers.
Getting started
Load the tidyverse, gtsummary, usdata, and sjPlot packages, and get the gerrymander data out of the usdata package. View the data using glimpse.
Each row is a US Congressional district. Here’s every variable in the data:
| variable | meaning |
|---|---|
district |
Congressional district ID |
state |
State the district is in |
party16 |
Party that won the district’s House election in 2016 |
clinton16 / trump16 |
Percent of the vote each candidate got in that district in the 2016 presidential election |
dem16 |
Whether a Democrat won that district’s House seat in 2016 |
party18 |
Party that won the district’s House election in 2018 |
dem18 |
Whether a Democrat won that district’s House seat in 2018 |
flip18 |
Whether the district’s House seat flipped from Republican to Democrat in the 2018 election. (0: no flip, -1: D to R, 1: R to D) |
gerry |
Prevalence of gerrymandering — low, mid, or high. “Prevalence” here just means how strongly that district’s lines were drawn that way — not whether it happened at all, but how much. |
This view, a table or document that connects a variable name (computer readable) to the meaning of the variable (human readable) is called a data dictionary or codebook.
Explore
1. Congressional districts per state
Which state has the most congressional districts? The least? How many congressional districts are there in this state? Use functions such as table, tbl_summary or count.
2. Districts at the tails
Make side-by-side box plots of percent of vote received by Trump in the 2016 Presidential Election by prevalence of gerrymandering. Identify any Congressional Districts that are potential outliers — points that fall well outside the whiskers of their box, meaning that district’s Trump vote share was unusually high or low compared to other districts with the same gerrymandering prevalence. What information can you share about them?
3. Gerrymandering and flipping
This relationship can be looked at from two directions — does gerrymandering predict a 2018 flip, and does a 2018 flip predict gerrymandering? Support both with a visualization and summary statistics. The plot answers “what does the mix look like within each group?”; the table gives the exact proportions the plot is showing. Write 1-2 bullet points about what you noticed from each plot. Use specific numbers in your answer.
Direction 1: Is a Congressional District more likely to have high prevalence of gerrymandering if a Democrat was able to flip the seat in the 2018 election? To compare the breakdown of gerrymandering prevalence within each flipped group, make sure flip18 is on the x axis and that your percents add up to 100% within each category.
Direction 2: Is a Congressional District more likely to be flipped to a Democratic seat if it has high prevalence of gerrymandering, or low prevalence? Same two variables, just flipped — so now gerry is on the x-axis. Again, make sure your percents add up to 100% within each category.
4. Gerrymandering and presidential margin
Using mutate, create a new variable, margin16, measuring how many percentage points Clinton won or lost by in each district (clinton16 - trump16). Does gerrymandering prevalence relate to how lopsided the 2016 presidential race was in that district? Report the min, mean, and max margin by gerry level, then visualize the full distribution with a violin + boxplot combo. Describe the shape, center, and spread of each group.