See here for the example code that generated this page
SanKey (Alluvial Diagram) Examples
This page demonstrates the interactive SanKey chart type in JSPlots.
- Flow visualization: Shows how entities transition between categories across time
- Long-format panel data: Each row represents one entity at one time point
- Switchable affiliations: Use dropdown to change which grouping to visualize
- Weighted flows: Ribbon width represents volume/value flowing between categories
- Interactive filtering: Filter data to focus on specific segments
Example 1: Voter Transitions (2012 → 2024)
Track how individual voters changed their party affiliation, employment status, and education level across four presidential elections.
This rich example demonstrates:
- Panel data: 2000 voters tracked across 4 elections (2012, 2016, 2020, 2024)
- Three switchable affiliations: Political party, Employment status, Education level
- Two value columns: Voter count and Weighted by turnout propensity
- Regional and age group filters for demographic analysis
- Realistic party switching patterns showing polarization trends
This Sankey diagram shows voter transitions across four presidential elections (2012, 2016, 2020, 2024). Use the 'Affiliation' dropdown to switch between party, employment, or education views. Use 'Weight By' to see raw counts vs. turnout-weighted flows. Filter by region and age group to analyze demographic patterns. Notice the increased party switching in 2016 and subsequent polarization in 2020-2024.
Example 2: Shopkeeper Budget Flow Analysis
Track individual money flows from revenue sources through total budget to spending destinations.
This example demonstrates:
- Flow tracking with explicit flow IDs (each dollar tracked from source to destination)
- Three stages: Revenue → Total Budget → Spending
- Legal vs illegal income streams (filter by tax return inclusion)
- Long format: Each flow represented by 3 rows (one per stage) sharing the same flow_id
- Shows how specific revenue sources fund specific expenses
This Sankey diagram shows money flows in a shopkeeper's budget. Each ribbon tracks specific money from its source (left) through total revenue (middle) to final destination (right). Use the filter to toggle between Legal and Illegal income streams. Notice how illegal income flows to Bitcoin and cash purchases while legal income pays regular expenses.
Summary
The SanKey chart type provides:
- Panel data visualization: Track entities across time periods
- Long-format data: Each row = one entity at one time point
- Required parameters:
id_col: Column identifying each entity
time_col: Column indicating time/stage (Date, Number, or OrderedCategorical)
color_cols: Column(s) for group affiliation
- Optional features:
value_cols: Weight the flows (default: equal weighting)
- Multiple color/value columns with dropdown switchers
- Filters to focus on segments
- Interactive controls: Switch affiliations and weights on the fly
- Automatic flow calculation: Tracks transitions between consecutive time periods
Use Cases
- Voter behavior analysis (party switching, demographic changes)
- Customer journey mapping and conversion funnel analysis
- Employee career progression and retention analysis
- Product lifecycle and market share evolution
- Patient health state transitions in medical studies
- Student progression through education levels
- Any entity-based transition analysis over time
Data Format Tips
- Each entity must have observations at each time point you want to include
- Missing time points = entity disappears from flow at that stage
- Time values are automatically sorted (works with dates, numbers, ordered categories)
- Use filters to focus on specific cohorts or segments
- Multiple affiliation columns let users explore different grouping perspectives