Weird Tableau 3:
Hi, thanks for reading! This newsletter is all about using Tableau in unique ways (ie. not what you typically find in YouTube tutorials, blog posts, and community forums, etc…). I’m calling it Weird Tableau because I couldn’t think of anything better. I hope you find it interesting, entertaining, and all that other good stuff. And if you do, please share and subscribe!
This edition is about using Tableau to identify gerrymandered redistricting maps. Gerrymandering sucks. Gerrymandering is what happens when politicians take the spirit of the US Constitution and give it a swirly.
No matter your political persuasion, gerrymandering should appall you. Both parties do it and they do it for the same reason: to restrict voters ability to elect anyone other than the governing party’s preferred candidate. You know what doesn’t suck? Using Tableau to counter gerrymandering and that’s what I’m writing about.
Unlike previous posts, this dashboard wasn’t a client deliverable. It’s something I built to analyze data more efficiently than was otherwise possible. My company (FLO Analytics) analyzed a bunch of maps for the ACLU-NH (US House, State House, State Senate, and Executive Council) and Tableau was critical every step of the way. You can read about the work on their website and I’ve included a couple other Tableau visuals at the bottom of this post. The dashboard I’m going to focus on is the one below. Keep reading to learn how it works.
The year was 2021. Across the United States, people who work for people who work for politicians huddled around maps like flesh flies on hippo dung, eager to perform a bizarre form of geographic casuistry, commonly known as gerrymandering 12. Against this mendacious backdrop, the American Civil Liberties Union of New Hampshire (ACLU-NH) reached out to my company, FLO Analytics with a query: could we help ACLU-NH assess redistricting maps proposed by New Hampshire’s state legislature? You betcha!
Evaluating redistricting maps for partisan shenanigans is one of those things that can be both really complicated and fairly straightforward. This project’s biggest challenge was the tight window between when the legislature proposed the maps and when they would vote on them. So, we needed to evaluate the maps fast. Like, really fast. Like so fast, you might get the impression the people proposing the maps didn’t want the public to look at them too long. But what am I talking about, that would never happen. Anyway, we chose a straightforward methodology to help us evaluate the maps within a day or two.
How we did it
Step 1: The first thing we needed to do was choose a method to calculate partisan lean (PL). PL measures the degree to which a district (or ward in NH’s case) votes for one party over the other. It is a standard measure used to assess redistricting maps (read more about PL at FiveThirtyEight). For our purposes, we only used the 2020 presidential election results3 and compared each voting ward in NH to how the country voted as a whole. For example, if the Republican party candidate received 48% of the votes in the USofA and 49% of the votes in a ward, that ward’s PL would be R+1. Note, that we use the two-party vote share. We’re only looking at votes for the Elephants and the Donkeys. Much like our political system, this analysis has no place for third parties.
Step 2: We needed two data sources to evaluate the maps: 1) the 2020 election vote totals for each voting district in the state and, 2) the voting district geographies. Election results are available on NH’s Secretary of State website and the voting ward boundaries live on NH geodata, brought to you by the University of New Hampshire (Go Wildcats!).
In a perfect world, I would join the vote totals to the geographies without any issues and move on (of course, there wouldn’t be gerrymandering in a perfect world, but that’s beside the point). However, as any data analyst will tell you, that never happens. I pulled both files into Tableau Prep to clear up mismatches in the join (did you know you can bring shapefiles into Tableau Prep now??? Tableau Tim does. Thanks Tableau Tim!). After some data cleaning magic, I exported two hyper files.
Step 3: Time to Tableau! Let’s start by calculating PL. The election results data table contained fields for the ward name, and each candidate’s vote totals.
Remember, PL is the percent share of the two-party vote total compared to the percent share of the two-party vote total in the US as a whole. The calculation needs to sum the vote totals, determine the percent share, and compare that value against the national vote share (the GOP candidate earned 47.7% of the national two party vote share in 2020). So, my calculated field looked like this.
Step 4: With the PL calculation ready it’s time to talk about sets, baby! The 1990’s were my formative years and I distinctly remember learning about Tableau sets from this post by Andy Cotgreave. Anytime I create a Tableau set, this song embeds itself deep within my auditory cortex. Now it does the same to you. You’re welcome! Ok, seriously let’s talk about
sex sets. Sets are fantastic. Who knew a stored boolean value could hold so much power (probably every computer scientist on earth). Sets are basically a True/False field. What’s special about them is you can tell Tableau whether records in your data are in the set (True) or not in the set (False). There are a number of ways to do this, I used set actions. Set actions assign values to a set based on interaction with a dashboard. Set actions have a ton of useful applications and there are lots of great tutorials that cover them (Andy Kriebel, PlayfairData, and more. Just google it).
Here, the sets act as a surrogate for the Congressional districts (NH 1 or NH 2), allowing me to calculate the PL of the records (voting wards) I assign to Set 1 (NH 1) and Set 2 (NH 2). I started by creating two empty sets - CongDist 1 and CongDist 2. Then, I created a calculated field called CongDists that assigns the value “Cong Dist 1”, to records in the set CongDist 1, “Cong Dist 2” to records in CongDist 2, and “Unassigned” to records that aren’t in either set. The CongDists field gets placed on the color tile in the map. At this point, there aren’t any records in either set, so all the wards are “unassigned” and colored gray.
Step 5: Time to make the diverging bar chart showing the PL for NH Congressional District’s 1 and 2. This is another useful chart type that lot’s folks have posted tutorials on. If you want to learn to make one, check out this post from PlayfairData. When my chart is set up, it looks like this.
Now, you may be asking yourself “where’s the chart?” Well, it’s there, I promise. It’s just that I haven’t assigned any records to either of the sets (Congressional Districts), so at this point the chart is blank.
Step 6: I’ve got a grayed out map and a blank diverging bar chart. Time to bring it all together in a dashboard. I added the map and chart and created two set actions, one to add wards to a district and one to remove them. I select “menu” under the “run action on” option so it runs when I click a link within the tool tip.
Now, when I select wards in the map and add them to one of the two districts, Tableau sums the vote counts and calculates the aggregated PL.
What made this dashboard so helpful was that when built, I only needed to draw the proposed maps in the dashboard to calculate the PL of the districts. It’s hard to understate just how much time this saved me.
Here are a couple other visuals (which depict a textbook “pack and crack” scheme.) I produced in Tableau to support other aspects of this work.
Thanks for reading! Please remember to share, subscribe, and give a big ol’ middle finger to gerrymanderers!
the practice of dividing or arranging a territorial unit into election districts in a way that gives one political party an unfair advantage in elections - Merriam-Webster
The practice of redistricting is not inherently unfair. In fact, the redistricting process was adopted to ensure fair representation (learn more about redistricting here: https://redistricting.lls.edu/redistricting-101/what-is-redistricting/).
Other PL methods consider averages across multiple elections over longer periods of time. They may also compare against the state as a whole rather than the country.