Quantcast
Channel: maps for developers - Medium
Viewing all articles
Browse latest Browse all 2230

Deep dive into our new election tilesets

$
0
0

Tips for analyzing data from the past four presidential elections

Margin of victory in 2004

By: Lo Bénichou

In our recent launch of Mapbox Elections, a hub of resources for building and publishing electoral maps, we included tilesets of past electoral results. These tilesets focus on general presidential election results from 2004 to 2016 per counties and states, and include additional statistics like population count from the US census, percentage of voter turnout, and land area.

Combined with the results of the 2020 primaries and general election, this data can be used to add context, explore trends, and go beyond simply displaying electoral returns.

Highlight trends over time

Use various properties to compare on election year to the next. For instance, we can see in the data that eleven counties consistently flipped every election. Using Studio or Mapbox GL JS, create a fill layer and use the {year}_winner property to color counties and the FIPS property to highlight them when selecting the data.

Counties that flipped every presidential election since 2004

To achieve this effect, use the match expression below. For the fill layer, click on “Style” and then “Color” to assign colors based on the {year}_winner property. To filter the counties, click on “Select data” and then “Filter.” Then, access the JSON console, by clicking on <> at the bottom right corner of the panel.

JSON console in Mapbox Studio

To filter by FIPS:

To color counties by winner:

Need more inspiration on what electoral trends to look for? Check out this article from the Washington Post and try to recreate some of these maps in Studio.

Do the math, in Studio

The new tilesets also contain basic statistical information on each county like population count and land area in square kilometers. With this information, you can calculate and style a map based on population density.

In Studio, use the panel to the left to calculate population density by dividing population count by land area. In the map below the color represents the party’s vote share in each county and the opacity represents its population density.

Vote shares and population density

To color each county based on the dominating party, we use a case and a stepexpression. When the margin of victory in a county is small (less than 5%), we use purple.

To determine the opacity, we use the /expression to divide population count with land area like so:

Join external data to add more context

If you want to go beyond population density, you can also add your own data to these tilesets. The FIPS code (unique identifier) for each county and state is provided as a feature id and a property. Using feature-state and Mapbox GL JS, you can join additional US Census data like age or income distribution, or financial data like campaign finance.

“Bernie Sanders won the race for Democratic donors in 2019,” Washington Post

Ready to start building? Check out our presidential election tileset page to get started or go to our election page for more resources to help you build impactful election maps. And for extra support, email us directly at elections@mapbox.com

Lo Bénichou


Deep dive into our new election tilesets was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.


Viewing all articles
Browse latest Browse all 2230

Trending Articles