Mapping in Tableau Activity Guide
Activity Guide
With this activity guide you will create several maps and charts to explore the 2016 presidential election popular vote results. See the end of this document for data source information
Download the data: go.ncsu.edu/tableau-mapping
- Open Tableau Public (or Tableau Desktop)
- In the "Connect Panel" under "To a File" select "Microsoft Excel"
- Select "us_state_level_pres_elec_results_2016.xlsx"
- The file will appear as a connection in the "Data Source" tab presented as a spreadsheet
- Observe the dataset
-
Click on the "Sheet 1" tab to open a Worksheet view
-
Click and drag:
-
"Measure Values" to the "Columns" field
-
"Measure Names" to the "Rows" field
-
-
In the "Filters" card click on the "Measure Names" dropdown and select "Edit Filter..."
-
Select "None" to remove all values
-
Select "Democrat," "Republican," and "Other" and then click "OK"
-
Sort the bar chart in descending order using the "Sort Button"
-
Click and drag "Measure Names" to the "Color button" in the "Marks card"
-
Click on the "Color button", select "Edit Colors…" and change the ""Democrat" bar to blue, the ""Republican" bar to red, and the "Other" bar to orange
-
Click and drag "Measure Values" to "Label" in the "Marks card"
-
Click on the "Label button" and set "Horizontal" alignment to "Center"
-
Double-click on the x-axis title, "Value," and change the "Title" to "Total Votes"
-
Observe the bar graph
-
Click on the "Data Source" tab
-
In the "Connections" panel select "Add"
-
In the "Add a Connection popup menu" select "Spatial File"
-
Select "us_states_geo.geojson"
-
In the "Connections" panel under "Files" double-click "us_states_geo.geojson" to create a relation between the existing and new dataset.
-
In the "Edit Relationship" popup create a relationship using the "Fips" field from the "state_FIPS" dataset equal to the "State Fips" field from the newly added geojson file
-
Observe the data
-
Create a new Worksheet by clicking the "Add Worksheet" icon
-
Double-click the "Geometry" field under "us_states_geo.geojson" in the data panel
-
Click and drag "Winner" to the "Color button" in the "Marks card"
-
Change the category colors on the map to match the bar chart
-
Observe the map
-
In the "Analysis menu" select "Create Calculated Field…"
-
Title the new calculation "Vote Margin"
-
Use the following calculation:
[Democrat] - [Republican]
-
Click "OK" to create the new field
-
Observe the new field in the "Data Source" view (click on the "state_FIPS" logical table to view the table with this field)
-
In "Sheet 2" drag the newly created "Vote Margin" to "Color" in the "Marks card"
-
Click the dropdown menu on the newly add "Vote Margin" field in the "Marks card" and select "Dimension" to set the role of this field as a continuous dimension
-
Click on the "Color button" in the "Marks card", select "Edit Colors…" and change the Palette to "Red-Blue-White Diverging"
-
Observe the map
-
Click on the "Data Source" tab
-
Click the "Change Data Source Button" and select "New Data Source"
-
Select "Text file" and open "county_level_election_results_2016.csv"
-
Observe the dataset. "County Name" has been given a "Geographic Role"
-
Create a new Worksheet by clicking the "Add Worksheet" icon
-
Double-click "County Name" to automatically populate our sheet with a map and georeferenced values (currently represented by dots)
-
In the "Marks card" select the dropdown and choose "Map" to create a map of county polygons
-
Observe the map. Tableau does a pretty good job of recognizing the names of places, like counties in this case. However, there are a few holes in our data that need to be fixed
-
In the bottom right-hand corner of the map click the "3 unknown" dialogue
-
Select "Edit locations…"
-
Use the dropdown menu in each row to find the likely matching location given the "Your Data" value
-
There is still one value in Alaska that is displayed as "Null". Using a Google search you found out it should be "Denali"... click "OK" when done
-
Click and drag "Winner" to the "Color button"
-
Click the "Color button" and under "Effects" set the "Border" to "None"
-
Change the colors to match our previous visualizations
-
Observe the map
-
Create a new Worksheet by clicking the "Add Worksheet" icon
-
Double-click "County Name" to automatically populate our sheet with a map and georeferenced values
-
Color the dots by "Winner"
-
In the "Analysis" menu select "Create Calculated Field…"
-
Title this new calculation "Winning Party"s Total Votes"
-
Put in the following calculation:
IF [Votes Dem] > [Votes Gop] THEN [Votes Dem] ELSE [Votes Gop] END
-
Click "OK" to run the calculation
-
A new measure titled "Winning Party"s Total Votes" will appear under the "Measures panel"
-
Click and drag "Winning Party"s Total Votes" to the "Size button"
-
Click on the "Data Source" tab
-
Click the "Change Data Source Button" and select "New Data Source"
-
Select "Spatial file" and open "2016_us_county_pres_elec_w_CVAP.shp"
-
Click "Update Now" if the data table does not populate with values
-
Observe the dataset
-
Create a new Worksheet by clicking the "Add Worksheet" icon
-
Double-click "County" to automatically populate our sheet with a map and georeferenced values. Observe the map. Alaska does not show up in this case since this dataset uses Alaska districts, which do not have a defined geographic role
-
In the "Worksheet menu" select "Clear" and then "Sheet"
-
Double-click "Geometry" to add the map of all the counties and Alaska districts
-
In the "Analysis" menu uncheck "Aggregate Measures"
-
Click and drag "Win Novote" to the "Color button"
-
Click the "Color button" and under "Effects" set the "Border" to "None"
-
Observe the map
-
Create a new Worksheet by clicking the "Add Worksheet" icon
-
Click and drag:
-
"Measure Values" to the "Columns" field
-
"Measure Names" to the "Rows" field
-
-
In the "Filters" field click on the "Measure Names" dropdown and select "Edit Filter..."
-
Select "None" to remove all values
-
Select "DEM," "REP," "No Vote," and "Other" and then click "OK"
-
Sort the bar chart in descending order using the "Sort Button"
-
Change the category colors to match our previous charts and set "No Vote" to light teal
-
Observe the bar graph
us_state_level_pres_elec_results_2016.xlsx, modified from:
- MIT Election Data and Science Lab, 2017, "U.S. President 1976–2016", https://doi.org/10.7910/DVN/42MVDX, Harvard Dataverse, V5
us_states_geo.geojson:
- ArcGIS.com, 2012, "states_basic", https://arcg.is/1DPSG4
county_level_election_results_2016.csv:
- 2016_US_County_Level_Presidential_Results.csv, https://github.com/tonmcg/US_County_Level_Election_Results_08-16/blob/master/2016_US_County_Level_Presidential_Results.csv
2016_us_county_pres_elec_w_CVAP.shp, modified from:
- MIT Election Data and Science Lab, 2018, "County Presidential Election Returns 2000-2016", https://doi.org/10.7910/DVN/VOQCHQ, Harvard Dataverse, V6
- TIGER/Line Shapefile, 2016, nation, U.S., Current County and Equivalent National Shapefile, https://catalog.data.gov/dataset/tiger-line-shapefile-2016-nation-u-s-current-county-and-equivalent-national-shapefile
- Alaska Division of Elections, Statewide Precinct Shape files, http://www.elections.alaska.gov/Core/districtmaps.php
- The U.S. Census Bureau, CVAP 2012-2016 5 Year ACS Data - CSV Format, https://www.census.gov/programs-surveys/decennial-census/about/voting-rights/cvap.2018.html