10 min read

Tutorial: Building a Presidential Election Dashboard in Tableau

Tutorial: Building a Presidential Election Dashboard in Tableau

One week remains before Election Day in the United States. That means that one of the most well-known data visualizations will resurface. Every four years we dust off the Electoral College map. How ever you choose to track the election this year, you will see some variation of the following map:

A Mercator Map showing US election results in varying shades of red and blue.

In the few years that I have been a Tableau user, I appreciate how simple it is to put data on a map. This election cycle, I wanted to build a Tableau dashboard that allows users to test their own electoral map.

In June 2020, I published my first rendition of this type of visualization. It used set actions and worked pretty well on Tableau Desktop. When I published this dashboard to Tableau Public, it failed to function as intended. Over the past four months, I have been stewing over the best way to create a solution. The function I was targeting let users click on states and assign them to their desired candidate.

Several days ago, I figured out the functionality. The following tutorial will show you how to build the Electoral College dashboard displayed below.

Before We Get Started

The first decision to make for this visualization was around how to display the States. I also required it to account for Washington DC and the Congressional Districts of Maine and Nebraska. There are three basic options to choose from when selecting your map that have their own pros and cons:

Web Mercator Map

The Web Mercator is the most common map version out there in Tableau. I bet that almost every map presented on Election Night will be some variation of the Web Mercator. Of the options described here, it is the most accurate when representing states by land mass and in their proximity to surrounding states. The primary drawback to this map style is the tightly-packed states in the Northeast. It is almost impossible for a user to click on Washington DC, Rhode Island or Delaware on their first try since they are so small. In the version displayed below, Alaska and Hawaii have their own section. This allows the Contiguous 48 states to fill up a larger space. The Congressional Districts of Nebraska and Maine also have their own section.

A mercator map showing states in red or blue.

Cartogram Map

The Cartogram Map is the most interesting option for modeling the Electoral College. This map style standardizes states by their amount of Electoral College Votes. This view offers a more accurate visual representation of the allocation of votes. This standardized size also ensures that a user can be sure of their selection when they click on the map. This version is less accurate than the Web Mercator when representing states by land mass. It does an acceptable job at placing states where they would be on a map.

A cartogram map showing states in red and blue.

Hex Map

The Hex map is the option I chose for my version of the Electoral College dashboard. This map style standardizes the size of states so that a user can be sure when selecting a state. This version is less accurate than the Web Mercator when representing states by land mass  or by Electoral College Vote amount. This map does a somewhat acceptable job at placing states roughly where they would be on a map. This map's largest advantage is that it presents a clean and uniform appearance.

A hex map with states of standardized sizes appearing in red and blue.

Your Data Source

You need a very simple dataset to start building this visualization. For label values, you need two values: 

  • State or Congressional District Abbreviation
  • Electoral College Vote amount

For tooltips, you need one more field, a State Display Name.

Here is a Comma-separated value list you can use for the 2020 Presidential Election:

Display_Name,State_Abbreviation,Electoral_College_Votes

Alaska,AK,3

Alabama,AL,9

Arkansas,AR,6

Arizona,AZ,11

California,CA,55

Colorado,CO,9

Connecticut,CT,7

District of Columbia,DC,3

Delaware,DE,3

Florida,FL,29

Georgia,GA,16

Hawaii,HI,4

Iowa,IA,6

Idaho,ID,4

Illinois,IL,20

Indiana,IN,11

Kansas,KS,6

Kentucky,KY,8

Louisiana,LA,8

Massachusetts,MA,11

Maryland,MD,10

Maine (Statewide),ME,2

Maine 1st Congressional District,ME-1,1

Maine 2nd Congressional District,ME-2,1

Michigan,MI,16

Minnesota,MN,10

Missouri,MO,10

Mississippi,MS,6

Montana,MT,3

North Carolina,NC,15

North Dakota,ND,3

Nebraska (Statewide),NE,2

Nebraska 1st Congressional District,NE-1,1

Nebraska 2nd Congressional District,NE-2,1

Nebraska 3rd Congressional District,NE-3,1

New Hampshire,NH,4

New Jersey,NJ,14

New Mexico,NM,5

Nevada,NV,6

New York,NY,29

Ohio,OH,18

Oklahoma,OK,7

Oregon,OR,7

Pennsylvania,PA,20

Rhode Island,RI,4

South Carolina,SC,9

South Dakota,SD,3

Tennessee,TN,11

Texas,TX,38

Utah,UT,6

Virginia,VA,13

Vermont,VT,3

Washington,WA,12

Wisconsin,WI,10

West Virginia,WV,5

Wyoming,WY,3

That’s all you need to get started!

Creating the Hex Map

With our data source imported, we need a grid of coordinates to serve as the backbone for this dashboard. These calculated fields create X and Y coordinates, they are Hex_Column and Hex_Row.

Hex_Column

CASE [Display Name]

WHEN 'Alabama' THEN 15

WHEN 'Alaska' THEN 1

WHEN 'Arizona' THEN 6

WHEN 'Arkansas' THEN 12

WHEN 'California' THEN 4

WHEN 'Colorado' THEN 7

WHEN 'Connecticut' THEN 22

WHEN 'Delaware' THEN 21

WHEN 'District of Columbia' THEN 19

WHEN 'Florida' THEN 17

WHEN 'Georgia' THEN 16

WHEN 'Hawaii' THEN 1

WHEN 'Idaho' THEN 4

WHEN 'Illinois' THEN 12

WHEN 'Indiana' THEN 14

WHEN 'Iowa' THEN 10

WHEN 'Kansas' THEN 10

WHEN 'Kentucky' THEN 13

WHEN 'Louisiana' THEN 11

WHEN 'Maine (Statewide)' THEN 24

WHEN 'Maine 1st Congressional District' THEN 23

WHEN 'Maine 2nd Congressional District' THEN 25

WHEN 'Maryland' THEN 17

WHEN 'Massachusetts' THEN 21

WHEN 'Michigan' THEN 15

WHEN 'Minnesota' THEN 9

WHEN 'Mississippi' THEN 13

WHEN 'Missouri' THEN 11

WHEN 'Montana' THEN 5

WHEN 'Nebraska (Statewide)' THEN 9

WHEN 'Nebraska 1st Congressional District' THEN 22

WHEN 'Nebraska 2nd Congressional District' THEN 24

WHEN 'Nebraska 3rd Congressional District' THEN 26

WHEN 'Nevada' THEN 5

WHEN 'New Hampshire' THEN 22

WHEN 'New Jersey' THEN 20

WHEN 'New Mexico' THEN 7

WHEN 'New York' THEN 19

WHEN 'North Carolina' THEN 18

WHEN 'North Dakota' THEN 7

WHEN 'Ohio' THEN 16

WHEN 'Oklahoma' THEN 9

WHEN 'Oregon' THEN 3

WHEN 'Pennsylvania' THEN 18

WHEN 'Rhode Island' THEN 23

WHEN 'South Carolina' THEN 17

WHEN 'South Dakota' THEN 8

WHEN 'Tennessee' THEN 14

WHEN 'Texas' THEN 8

WHEN 'Utah' THEN 8

WHEN 'Vermont' THEN 20

WHEN 'Virginia' THEN 16

WHEN 'Washington' THEN 3

WHEN 'West Virginia' THEN 15

WHEN 'Wisconsin' THEN 11

WHEN 'Wyoming' THEN 6

END

 

Hex_Row

CASE [Display Name]

WHEN 'Alabama' THEN 3

WHEN 'Alaska' THEN 9

WHEN 'Arizona' THEN 4

WHEN 'Arkansas' THEN 4

WHEN 'California' THEN 4

WHEN 'Colorado' THEN 5

WHEN 'Connecticut' THEN 6

WHEN 'Delaware' THEN 5

WHEN 'District of Columbia' THEN 5

WHEN 'Florida' THEN 1

WHEN 'Georgia' THEN 2

WHEN 'Hawaii' THEN 1

WHEN 'Idaho' THEN 6

WHEN 'Illinois' THEN 6

WHEN 'Indiana' THEN 6

WHEN 'Iowa' THEN 6

WHEN 'Kansas' THEN 4

WHEN 'Kentucky' THEN 5

WHEN 'Louisiana' THEN 3

WHEN 'Maine (Statewide)' THEN 8

WHEN 'Maine 1st Congressional District' THEN 2

WHEN 'Maine 2nd Congressional District' THEN 2

WHEN 'Maryland' THEN 5

WHEN 'Massachusetts' THEN 7

WHEN 'Michigan' THEN 7

WHEN 'Minnesota' THEN 7

WHEN 'Mississippi' THEN 3

WHEN 'Missouri' THEN 5

WHEN 'Montana' THEN 7

WHEN 'Nebraska (Statewide)' THEN 5

WHEN 'Nebraska 1st Congressional District' THEN 1

WHEN 'Nebraska 2nd Congressional District' THEN 1

WHEN 'Nebraska 3rd Congressional District' THEN 1

WHEN 'Nevada' THEN 5

WHEN 'New Hampshire' THEN 8

WHEN 'New Jersey' THEN 6

WHEN 'New Mexico' THEN 3

WHEN 'New York' THEN 7

WHEN 'North Carolina' THEN 4

WHEN 'North Dakota' THEN 7

WHEN 'Ohio' THEN 6

WHEN 'Oklahoma' THEN 3

WHEN 'Oregon' THEN 5

WHEN 'Pennsylvania' THEN 6

WHEN 'Rhode Island' THEN 7

WHEN 'South Carolina' THEN 3

WHEN 'South Dakota' THEN 6

WHEN 'Tennessee' THEN 4

WHEN 'Texas' THEN 2

WHEN 'Utah' THEN 4

WHEN 'Vermont' THEN 8

WHEN 'Virginia' THEN 4

WHEN 'Washington' THEN 7

WHEN 'West Virginia' THEN 5

WHEN 'Wisconsin' THEN 7

WHEN 'Wyoming' THEN 6

END

 

Use continuous dimensions with Hex_Column on the columns shelf and Hex_Row on the rows shelf. We have the starting point for our map:

Tableau Dashboard screenshot showing dots on a grid representing the 50 states.

Switch the type of mark to “Shape”, and set the shape to a hexagon. If you do not have a hexagon in your shapes, you can download one and save it into the “Shapes” folder within your “My Tableau Repository” folder. Adjust the hexagon size so they tessellate well once you place this worksheet on the dashboard. When updated, the hexagon map looks like this:

A Tableau dashboard screenshot showing the 50 states as black hexagons.

Creating Outcome Placeholders

Each State and Congressional Districts will have a user-modifiable outcome. You will need to create a unique assignment parameter for every location in your dashboard - my dashboard has 56 unique parameters. This is where you can define the number of options for your user within these parameters. In my example, I have five potential options that represent the following outcomes:

  • Solid - Biden
  • Lean - Biden
  • Toss Up
  • Lean - Trump
  • Solid - Trump

A five-option parameter will look as follows once configured. This is an example of Alaska’s Assignment parameter:

Screenshot of Alaska's Assignment Parameter in Tableau.

Formatting Hexagons with Assignment

Now that the State and Congressional District assignments have been created, we need a field to merge them all into one. This calculated field sits in the Color section of the marks card.

Modified Assignment

IF [State Abbreviation] = "AL" THEN [AL Assignment] 

ELSEIF [State Abbreviation] = "AK" THEN [AK Assignment] 

ELSEIF [State Abbreviation] = "AR" THEN [AR Assignment] 

ELSEIF [State Abbreviation] = "AZ" THEN [AZ Assignment] 

ELSEIF [State Abbreviation] = "CA" THEN [CA Assignment] 

ELSEIF [State Abbreviation] = "CO" THEN [CO Assignment] 

ELSEIF [State Abbreviation] = "CT" THEN [CT Assignment] 

ELSEIF [State Abbreviation] = "DC" THEN [DC Assignment] 

ELSEIF [State Abbreviation] = "DE" THEN [DE Assignment] 

ELSEIF [State Abbreviation] = "FL" THEN [FL Assignment] 

ELSEIF [State Abbreviation] = "GA" THEN [GA Assignment] 

ELSEIF [State Abbreviation] = "HI" THEN [HI Assignment] 

ELSEIF [State Abbreviation] = "IA" THEN [IA Assignment] 

ELSEIF [State Abbreviation] = "ID" THEN [ID Assignment] 

ELSEIF [State Abbreviation] = "IL" THEN [IL Assignment] 

ELSEIF [State Abbreviation] = "IN" THEN [IN Assignment] 

ELSEIF [State Abbreviation] = "KS" THEN [KS Assignment] 

ELSEIF [State Abbreviation] = "KY" THEN [KY Assignment] 

ELSEIF [State Abbreviation] = "LA" THEN [LA Assignment] 

ELSEIF [State Abbreviation] = "MA" THEN [MA Assignment] 

ELSEIF [State Abbreviation] = "MD" THEN [MD Assignment] 

ELSEIF [State Abbreviation] = "ME" THEN [ME Assignment] 

ELSEIF [State Abbreviation] = "ME-1" THEN [ME-1 Assignment] 

ELSEIF [State Abbreviation] = "ME-2" THEN [ME-2 Assignment] 

ELSEIF [State Abbreviation] = "MI" THEN [MI Assignment] 

ELSEIF [State Abbreviation] = "MN" THEN [MN Assignment] 

ELSEIF [State Abbreviation] = "MO" THEN [MO Assignment] 

ELSEIF [State Abbreviation] = "MS" THEN [MS Assignment] 

ELSEIF [State Abbreviation] = "MT" THEN [MT Assignment] 

ELSEIF [State Abbreviation] = "NC" THEN [NC Assignment] 

ELSEIF [State Abbreviation] = "ND" THEN [ND Assignment] 

ELSEIF [State Abbreviation] = "NE" THEN [NE Assignment] 

ELSEIF [State Abbreviation] = "NE-1" THEN [NE-1 Assignment] 

ELSEIF [State Abbreviation] = "NE-2" THEN [NE-2 Assignment] 

ELSEIF [State Abbreviation] = "NE-3" THEN [NE-3 Assignment] 

ELSEIF [State Abbreviation] = "NH" THEN [NH Assignment] 

ELSEIF [State Abbreviation] = "NJ" THEN [NJ Assignment] 

ELSEIF [State Abbreviation] = "NM" THEN [NM Assignment] 

ELSEIF [State Abbreviation] = "NV" THEN [NV Assignment] 

ELSEIF [State Abbreviation] = "NY" THEN [NY Assignment] 

ELSEIF [State Abbreviation] = "OH" THEN [OH Assignment] 

ELSEIF [State Abbreviation] = "OK" THEN [OK Assignment] 

ELSEIF [State Abbreviation] = "OR" THEN [OR Assignment] 

ELSEIF [State Abbreviation] = "PA" THEN [PA Assignment] 

ELSEIF [State Abbreviation] = "RI" THEN [RI Assignment] 

ELSEIF [State Abbreviation] = "SC" THEN [SC Assignment] 

ELSEIF [State Abbreviation] = "SD" THEN [SD Assignment] 

ELSEIF [State Abbreviation] = "TN" THEN [TN Assignment] 

ELSEIF [State Abbreviation] = "TX" THEN [TX Assignment] 

ELSEIF [State Abbreviation] = "UT" THEN [UT Assignment] 

ELSEIF [State Abbreviation] = "VA" THEN [VA Assignment] 

ELSEIF [State Abbreviation] = "VT" THEN [VT Assignment] 

ELSEIF [State Abbreviation] = "WA" THEN [WA Assignment] 

ELSEIF [State Abbreviation] = "WI" THEN [WI Assignment] 

ELSEIF [State Abbreviation] = "WV" THEN [WV Assignment] 

ELSEIF [State Abbreviation] = "WY" THEN [WY Assignment] 

END

 

Edit the aliases of the Modified Assignment field to match the desired labeling:

Screenshot within Tableau showing how to edit the aliases of the modified assignment field.

Assigning Color Palette to Outcomes

Drag the Modified Assignment field to the Color section of the marks card. Assign the following colors:

  • Solid - Biden: #4878a6
  • Lean - Biden: #b9ddf1
  • Toss Up: #d6d6d6
  • Lean - Trump: #ffbeb2
  • Solid - Trump: #da323f

When applied, the hexagon map looks like this:

Screenshot of Tableau dashboard with the 50 states as hexagons, now colored.

Adding Labels to Hexagons

Drag State Abbreviation and Electoral College Votes into the Label section of the marks card. For these values to display on top of the hexagons, format them as follows:

Screenshot of values within Tableau.

When applied, the hexagon map looks like this:

Hexagon map now includes color, state labels.

Creating Next Value Calculations

To cycle through the potential outcomes, we need to create calculated fields. These fields will read the current value of the parameter and display the next value in the cycle. You will need to create a Next Value calculated field for each State or Congressional District. This is an example of Alaska’s Next Value field:

AK Next Value

IF [State Abbreviation] = "AK" THEN

(IF [AK Assignment] = 1 THEN 2

ELSEIF [AK Assignment] = 2 THEN 3

ELSEIF [AK Assignment] = 3 THEN 4

ELSEIF [AK Assignment] = 4 THEN 5

ELSEIF [AK Assignment] = 5 THEN 1

ELSE 3 END)

ELSE NULL END

 

Creating Vote Total KPIs for Each Candidate

To provide the user feedback about the running tally of Electoral College Votes, we need to create a summary by candidate. When a State or Congressional District belongs to a candidate, we want to count it toward their total. We also show a message that indicates if the candidate has received enough votes to win the election.

Electoral College Votes_Biden

{ FIXED : 

SUM(IF [Modified Assignment] = 1 OR [Modified Assignment] = 2

THEN [Electoral College Votes] ELSE 0 END) 

}

 

Electoral College Votes to Go_Biden

(IF [Electoral College Votes_Biden] < 270

    THEN STR(INT(270-[Electoral College Votes_Biden]))+" To Go" 

ELSE "Winner" END)

Screenshot reads 'Biden, 279 Electoral Votes, winner'

Electoral College Votes_Trump

{ FIXED : 

SUM(IF [Modified Assignment] = 4 OR [Modified Assignment] = 5

THEN [Electoral College Votes] ELSE 0 END) 

}

 

Electoral College Votes to Go_Trump

(IF [Electoral College Votes_Trump] < 270

    THEN STR(INT(270-[Electoral College Votes_Trump]))+" To Go" 

ELSE "Winner" END)

Screenshot reads 'Trump, 163 electoral votes, 107 to go'

Creating a Bar Chart to Summarize the Outcome

To aid the user in seeing how many Electoral College Votes a candidate has earned, we create a stacked bar chart. Electoral College Votes is in the Columns shelf and Modified Assignment is on the Color section of the marks card.

Fix the Electoral College Votes axis between 0 and 538:

Screenshot of Tableau to edit axis.

Add a Reference Line at 270 to show the number of votes needed to win:

Screenshot of Tableau to edit reference line.

When applied, the stacked bar chart looks like this:

Screenshot of stacked bar chart of varying colors, widths.

Creating a Reset to Default Button

To provide the user with a consistent starting point, we create a reset button. Since the assignment parameters ranged between 1 and 5, we include ad-hoc calculations in the Detail section of the marks card.

An example of one of these ad-hoc calculations is as follows:

AVG(1)

Switch the type of mark to “Shape”, and set the shape to a reset arrow. If you do not have an image of a reset arrow in your shapes, download one and save it into the “Shapes” folder within your “My Tableau Repository” folder. Increase the size of the reset arrow. The reset button looks like this:

Screenshot of reset button shaped like a circle with an arrow attached to the end.

Assembling your Dashboard

Drag the worksheets onto the dashboard canvas and arrange them as desired. This is also a great time to ensure that your tooltips are displaying the details that matter to you or your user. 

The dashboard looks like this:

Screenshot showing finished dashboard. Red and Blue hexagon map entitled 'The 2020 Race for the Presidency'

Creating Parameter Actions

To make the dashboard interactive, we need parameter actions to change outcome assignments.

Cycle Through Outcome Options

The intent of this dashboard is to allow the user to change the outcome of each State or Congressional District. To make this happen, we need to leverage parameter actions. For each location on the map, we create a parameter action. This action grabs the Next Value field and assigns it to the location assignment parameter. This is an example of Alaska’s Next Value parameter action:

Screenshot showing Alaska's Next Value parameter action

Reset Outcome Options to Default

After the user has modified several States or Congressional Districts, they may wish to start over. To make this happen, we need to leverage parameter actions. For each location on the map, we create a reset parameter action. This action takes a value and assigns it to the location assignment parameter. Default values for each location come from FiveThirtyEight’s Polls Plus Model: 

  • Solid - Biden: Biden leading by 10%+
  • Lean - Biden: Biden leading by at least 2.5%, but not by more than 10%
  • Toss Up: Neither candidate leading by more than 2.5%
  • Lean - Trump: Trump leading by at least 2.5%, but not by more than 10%
  • Solid - Trump: Trump leading by 10%+

This is an example of Alaska’s Reset parameter action:

Screenshot showing Alaska Reset Parameter Action

And There You Have It!

Here is an example of the finished visualization in action:

Hex map with red and blue hexagons, titled 'The 2020 Race for the Presidency'

That is how you build a Tableau dashboard that allows your user to change individual States or Congressional Districts outcomes using parameter actions. To view this visualization on Tableau Public, click on this link.

 


Explore More

What is a Data Monetization? | Unlock Revenue with Data Portals

What is a Data Monetization? | Unlock Revenue with Data Portals

Everyone says, "data is the new gold," and there are a few ways to actually create revenue generation using insights. One such method to unlock the...

Read More
What is Embedded Analytics? | Deliver Insights Directly to People

What is Embedded Analytics? | Deliver Insights Directly to People

Technology has revolutionized how businesses operate, with data being at the forefront of this transformation. The ability to analyze data and...

Read More
Demystifying Data Analytics for SMBs

Demystifying Data Analytics for SMBs

If there’s one problem that most businesses don’t have, it’s a lack of data. In fact, the amount of data in the world is expected to surpass 50...

Read More