The Sankey Diagram Mod displays a flow from one set of values to another, in which the width of the arrow is shown proportionally to the flow quantity.
Sankey diagrams (also called alluvial diagrams) are typically used to visualize energy or material or cost transfers between processes. They put a visual emphasis on the major transfers or flows within a system and are helpful in locating dominant contributions to an overall flow.
Data Requirements
Every mod handles missing, corrupted and/or inconsistent data in different ways. It is advised to always review how the data is visualized.
To make the Sankey Diagram Mod work properly a data table with at least four columns is required:
- One column should identify entities, for example, names of countries, people or objects.
- One column should contain measures for the country, person or object
- Two or more columns should contain categories, process steps, or contributions
Setting Up the Mod
Let's analyze electoral swing in last three US presidential elections and visualize how votes of people in respective states changed.
The data used for this visualization comes from Harvard Dataverse and contains constituency (state-level) returns for elections to the US presidency. See below for the required data preparation, or download the pre-configured dataset here.
State | State ISO | Electoral Votes | Party 2012 | Party 2016 | Party 2020 | Candidate 2012 | Candidate 2016 | Candidate 2020 |
---|---|---|---|---|---|---|---|---|
Alabama | AL | 9 | Republican | Republican | Republican | Romney, Mitt | Trump, Donald J. | Trump, Donald J. |
Alaska | AK | 3 | Republican | Republican | Republican | Romney, Mitt | Trump, Donald J. | Trump, Donald J. |
Arizona | AZ | 11 | Republican | Republican | Democrat | Romney, Mitt | Trump, Donald J. | Biden, Joseph R. Jr |
... | ... | ... | ... | ... | ... | ... | ... | ... |
Wisconsin | WI | 10 | Democrat | Republican | Democrat | Obama, Barack H. | Trump, Donald J. | Biden, Joseph R. Jr |
Wyoming | WY | 3 | Republican | Republican | Republican | Romney, Mitt | Trump, Donald J. | Trump, Donald J. |
A Sankey diagram can be configured to show the number of electoral votes per respective states over three years for the different candidates and also shows the link between the year for a state, thus showing that some states from 2012 Obama changed to 2016 Trump and then to 2020 Biden.
-
Add the Sankey diagram and use
Electoral Votes
on the X-axis -
Add
Candidate 2012
,Candidate 2016
andCandidate 2020
to the Y-axis -
Add
Candidate 2020
orParty 2020
to Color-by axis and adjust the colors to the parties? typical colors
Because the Sankey diagram also supports marking, you can create a detailed table visualisation then listing the actual state names and electoral votes to give you more details
Data Preparation
The data preparation contains a couple of steps to filter and pivot the data to get it in the right shape for the Sankey diagram.
The data set in the required format for the Sankey diagram with one row per state:
To create the required data structure with one line per entity and categories as columns from the original data source, several steps have to be done in Spotfire:
- Download the data as CSV from Harvard Dataverse
- Import the data into Spotfire
-
From the data panel:
-
Filter rows for
[year]>=2012
-
Create a new calculated column to identify why candidates got the most votes per state with
maxcandidatevotes using Max([candidatevotes]) Over ([year],[state])=[candidatevotes]
-
Filter rows for
[maxcandidatevotes]=True
-
Filter rows for
- From the data panel, then pivot the data with one row per state and create columns for candidate and party_simplified per year.
Using the Mod
Marking
You can mark a single flow by clicking it, mark several flows by Ctrl-clicking on them or mark categories of flows by clicking on the categories. Clicking in the empty space in between flows will clear the marking.
Building the Project
In a terminal window:
- npm install
- npm start
In a new terminal window:
- npm run server
Help and Support
This Mod is not supported by Spotfire® Support.
In the event of issues or to suggest features and enhancements, submit an issue in the Mod's GitHub repository.
For general questions about Mods, please post a question in the Forum for Extensions & Mods to make it visible and routed to the appropriate team(s) to respond.
More Information About Spotfire® Mods
- Spotfire® Community Exchange: A safe and trusted place to discover ready-to-use Mods
- Developer Documentation: Introduction and tutorials for Mods developers
- Mods code examples on GitHub: A public repository for example projects
Recommended Comments
There are no comments to display.