Function Repository Resource:

AlluvialFlowChart

Source Notebook

Chart changing weights over multiple stages

Contributed by: Karl Fraser

ResourceFunction["AlluvialFlowChart"][flows,categories,stages]

generates an alluvial chart of flows over categories through stages.

Details and Options

ResourceFunction["AlluvialFlowChart"] returns a DynamicModule object representing an Alluvial diagram, wherein the heights of the bands correspond to relevant categories weights, with nodes / categories grouped vertically. Horizontal steps represent the sequence of graph stages. Hovering over a category or stage hides all flows not entering or exiting that item.
The following options can be given:
"BlockWidth"0.25width of stage blocks
"HorizontalSpacing"2.4horizontal gap between stage blocks
"SortBySize""Groups"sort by stage groups
"RibbonCurveFactor"0.75how much the ribbons curve
"MinFlowThreshold"3minimum value to show
"ShowPercentages"Falsewhether to show the percentages
LabelStyleDirective[FontFamily\"Arial\",FontWeightBold]label styling
"ValueStyle"Directive[FontFamily\"Arial\",FontSize9.5]value styling

Examples

Basic Examples (2) 

Construct a simple 2-stage alluvial diagram:

In[1]:=
ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{{(*A->{Public,Private,
   Unemployed}*){4, 2, 2},(*B*){2, 4, 2},(*C*){2, 4, 3}}},
 {(*district*){"A", "B", "C"},(*employed*){"Public", "Private", "Unemployed"}},
 (*stages*){"District", "Employment"}, "ImageSize" -> 400]
Out[1]=

When the mouse is moved over a stage, neighbouring connected stages are highlighted with their values updated accordingly:

In[2]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400]

Options (10) 

BlockWidth (1) 

Specify the size of the stage blocks:

In[3]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals};
ResourceFunction[
    "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 300, "BlockWidth" -> #] & /@ {0.25, 0.5, 1} // Row
Out[4]=

HorizontalSpacing (1) 

Specify the size of the horizontal gap between the stage blocks, where the spacing specification can be a single list value that is used for all or a list of values that will be used accordingly:

In[5]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "HorizontalSpacing" -> {1, 2}]
Out[6]=

ShowPercentages (1) 

Specify whether or not to show the stage blocks percentage value in the block rather than the raw value:

In[7]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "ShowPercentages" -> True]
Out[8]=

SortBySize (3) 

Specify whether a sort function is to be applied to the stages. With the setting "Groups", AlluvialFlowChart tries to minimize flow crossings:

In[9]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> "Groups"]
Out[10]=

True - sort each stage big to small values:

In[11]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> True]
Out[12]=

fallback - sort each stage by reverse categories:

In[13]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> False]
Out[14]=

RibbonCurveFactor (1) 

Specify the smoothness of the ribbon curves:

In[15]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; 
ResourceFunction[
    "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 300, "RibbonCurveFactor" -> #] & /@ {0.1, .5, 1} // Row
Out[16]=

MinFlowThreshold (1) 

Specify the minimum ribbon value that will be shown in the chart:

In[17]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; 
ResourceFunction[
    "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 300, "MinFlowThreshold" -> #] & /@ {1, 3, 4} // Row
Out[18]=

LabelStyle (1) 

Specify a function that generates the style of the label element of the stage block:

In[19]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "LabelStyle" -> Directive[FontFamily -> "Arial", FontWeight -> Bold]]
Out[20]=

ValueStyle (1) 

Specify a function that generates the style of the value element within the stage block:

In[21]:=
stages = {"District", "Employment", "Usage"};
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction[
 "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, stages, "ImageSize" -> 400, "ValueStyle" -> Directive[FontFamily -> "Arial", FontSize -> 20]]
Out[25]=

Properties and Relations (1) 

The ResourceFunction AlluvialChart has simpler visual functionality and fewer refinement options. Additionally, there is no mouseover functionality to show flows between neighbouring stages:

In[26]:=
gs = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1}, VertexWeight -> #] & /@ {{1, 2, 6}, {3, 2, 3}, {6, 2, 1}};
alluvialChart = ResourceFunction["AlluvialChart"][gs, ImageSize -> 250];
categories = {(*district*){"A", "B", "C"},
   (*employed*){"Public", "Private", "Unemployed"},
   (*usage*){"Open", "Closed", "Shared"}};
employmentTotals = {(*A->{Public,Private,
   Unemployed}*){3, 2, 2},(*B*){2, 4, 2},(*C*){3, 4, 3}};
usageTotals = {(*Public->{Open,Closed,
   Shared}*){0, 1, 0},(*Private*){1, 1, 2},(*Unemployed*){0, 4, 1}};
flows = {employmentTotals, usageTotals};
alluvialFlowChart = ResourceFunction[
   "AlluvialFlowChart", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][flows, categories, {"A", "B", "C", "D", "E"},
    "ImageSize" -> 300, "LabelStyle" -> Directive[FontFamily -> "Arial", FontWeight -> Italic]];
Row[{alluvialChart, alluvialFlowChart}]
Out[27]=

Publisher

Karl Fraser

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.1 – 05 June 2026
  • 1.0.0 – 03 June 2026

Related Resources

License Information