The gender income gap, squared
November 14th, 2024
3 min
This article is brought to you by Datawrapper, a data visualization tool for creating charts, maps, and tables. Learn more.
Shaylee here, from Datawrapper’s Customer Success & Support team. This week, I’m searching for common search interests between different U.S. states.
2024 is a year of elections, with around half of the world’s population eligible to vote in one of more than 75 national and international elections this year. The upcoming presidential election in the United States has been especially on my mind — and of course, where there’s elections, there’s data to be visualized.
Before an election actually happens, one way to guess what voters are thinking is to look at the topics they search for online. Are red and blue states googling the same topics, or are they thinking about totally different issues? Do swing states follow any patterns, and if so, can we use them to predict election outcomes?
I started by going to FiveThirtyEight’s election dashboard, which includes a simulation of 100 possible election outcomes for each state:
While many states are clearly likely to vote for one party or the other, some states are swing states and could go either way. These are marked with our new pattern overlays!
Next, I pulled a month’s worth of data from Google Trends on 14 election-related search topics, including unemployment, Social Security, crime, healthcare, and climate change. Google Trends tracks the popularity of a search topic over time, from 0 (not even enough data to index that term) to 100 (an all-time popularity peak for that term in that region).
This data isn’t one-dimensional, so it doesn’t fit as neatly on a choropleth map. Instead, I want to use tooltips for each state to show local search terms, their relative popularity, and how that state compares with others. Enter the tooltip functions JOIN, MAP, SORT, and SLICE. With those functions, we can create a sorted list of the top five search results by state, and take a look at what patterns emerge.
Across the country, minimum wage was the most popular issue — 38 states had minimum wage included in their top six searches, and nine states had it as their most searched topic overall. It was followed closely by healthcare, inflation, crime, and homelessness. Crime in particular was the top topic in 11 states, and there were only 16 states without crime in their top six issues.
I did find some surprising commonalities between individual states. For example, Delaware and Tennessee, solidly blue and red states respectively, have similar rates of searches for voter registration, healthcare, and supplementary security income. Some states had the exact same top searches in the exact same order, like Georgia, California, Virginia, and New York.
Of course, search tracking can’t tell where individuals stand on each topic, or what they mean in people’s everyday lives. Both presidential candidates talk about issues like healthcare and crime, but they have wildly different plans for what to do about them. Still, commonalities across states can be a clue towards understanding what topics are on voters’ minds, regardless of where they live.
First off, we’ll organize the data into an array, naming which data columns should be grouped together and using square brackets to delineate those groups. This essentially tells Datawrapper what information to use in the tooltip functions that follow; in this case, the name of my search topic is d[0]
, and the value of that search according to Google Trends is d[1]
.
[[ topic1Name, topic1Value ],[ topic2Name, topic2Value ],[topic3Name, topic3Value]…]
Then, we’ll apply a SORT
function to that array, where:
TRUE
) or descending (FALSE
). Here we want to sort from largest to smallest value, so we'll use FALSE
.SORT(array, FALSE, '1')
Next, the SLICE
function will pull out just the top five results — we'll need to input our array, as well as the locations to start and end the slice (in this case, from the first number in our array to the fifth):
SLICE(sorted_array, 0, 5)
We can also use a FILTER
function to filter out any entries that aren’t greater than zero:
FILTER(f(s) = s[1] > 0, sliced_sorted_array
Now we have a set of data to use in our tooltips. We’ll build each tooltip row by row, one row for each individual group defined in our array, using the CONCAT
function:
CONCAT("<tr><td>", d[0],"</td><td>",d[1],"</td></tr>")
Finally, we’ll plug that all into a MAP
function, which creates a new row in the table for each group, and JOIN
the rows together for a fully formatted, sorted table in each tooltip:
JOIN(MAP(f(d) = table_formula, filtered_sorted_array),"")
These functions can be used to create organized tables, write sentences from separate bits of information, and even sort tiny bars within tooltips — the maps in this post include examples of all of these methods. To take a closer look, you can hover over the map and click "Edit this chart" to create a copy of the map in your own Datawrapper account! If you’re looking to explore even more functions that can be used in tooltips, you’ll find documentation on all possible expressions in this Github Readme.
Thanks for reading! Drop any interesting commonalities you see in the comments — and don’t forget to vote if you can! Next week, stay tuned for a Weekly Chart from my colleague Jack.
Comments