Jump to content
  • Version 1.0.0, released July 2021

    CommunityExchange.png.77e051ce29bad4af35aa797f119abc2d.png

    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.

    image.thumb.png.40d6e4f72888f61c69e4a4d4fa2dd489.png

    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.

    SankeyDiagram.png.8f5cd6a004a37810dc11c18a99e77cd8.png

    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.

    1. Add the Sankey diagram and use Electoral Votes on the X-axis
    2. Add Candidate 2012Candidate 2016 and Candidate 2020 to the Y-axis
    3. Add Candidate 2020or Party 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:

     

    RowstoColumns.png.bb0519a8cdaac596dc254b8fd2f948cd.png

    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:

    1. Download the data as CSV from Harvard Dataverse
    2. Import the data into Spotfire
    3. From the data panel:
      1. Filter rows for [year]>=2012
      2. Create a new calculated column to identify why candidates got the most votes per state with maxcandidatevotes using Max([candidatevotes]) Over ([year],[state])=[candidatevotes]
      3. Filter rows for [maxcandidatevotes]=True
    4. 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

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...