How To: FiveThirtyEight Electoral College Cartograms in Tableau

9/28/2016 Matt Chambers 6 Comments




A lot of my previous work has been centered around custom maps or mapping techniques within Tableau.  I've always been fascinated with FiveThirtyEight's custom Electoral College cartogram used in their 2016 election forecast.  This type of cartogram was created in response to critiques about the use of geographic maps to show election data.

So here's how I did it in Tableau.  I happened to see a post that shows several different cartograms that are currently being used for the election.  In this post, you will see that the SVG for the different cartograms is there.  I took the SVG, converted it to a shapefile, and used the Alteryx Gallery tool to convert it to a CSV.  I did some manual matching to get the state abbreviations paired with the polygons as well.

Once I had the CSV, I was able to build it in Tableau.  Here's how it's done.

1. Download the file for the polygons

2. Open Tableau and connect to the data source.  In this case, I am joining another data set so that I can color the states by the candidates' chances of winning each state.  You will need to make sure your data set has a state abbreviation to join the polygon file to your data set.


3. Drag X to Columns and Y to Rows making sure the aggregation is AVG. Choose Polygon as the mark type and drag Polygon ID to Detail and Point ID to Path.


4. Drag Y to the Rows again making sure the aggregation is AVG.  Create a dual axis, synchronize the axes, and change the mark type to Text.  Drag the State Abbreviation to the Text mark card.



5. Drag the measure you'd like to color by to the Color mark.  Turn on the color borders.



6. Hide the headers, remove gridlines



Feel free to download the workbook and comment with questions.  I'm really excited to see how people use this for Tableau's election coverage.

6 comments:

  1. Love this! But I'm a little confused by Hawaii and Alaska... I think they might be flipped. The labels/colors/tooltips seem to be reversed from the correct shapes.

    ReplyDelete
    Replies
    1. Oh wow, great catch! When I mapped the polygons to their names, I must have switched those. It is fixed now, and the spreadsheet is fixed as well.

      Delete
  2. I have called out Nate Silver this year, challenging the need for complex predictive models in order to project the winner of the election (See my latest update here: https://www.linkedin.com/pulse/nate-silver-election-challenge-september-update-ken-flerlage) I've used Tableau for my maps and definitely plan to try this out. Thanks!

    ReplyDelete
    Replies
    1. Worked with this tonight and the results are fantastic. You can check out my updated election dashboard here: https://public.tableau.com/profile/ken.flerlage#!/vizhome/Election2016_7/Election2016

      Delete
    2. This looks great Ken! Glad you found the technique useful.

      Delete
  3. it's nice code .thank for sharing.

    gclub casino
    gclub

    ReplyDelete