Function Repository Resource:

AlluvialFlowChart (1.0.0) current version: 1.0.1 »

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 Graphics 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. 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 (1) 

Construct a simple 2-stage alluvial diagram:

In[1]:=
ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.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]=

Options (10) 

BlockWidth (1) 

Specify the size of the stage blocks:

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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals};
ResourceFunction["AlluvialFlowChart"][flows, categories, stages, "ImageSize" -> 400, "BlockWidth" -> #] & /@ {0.25, 0.5, 1} // Row
Out[3]=

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[4]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.0"][flows, categories, stages, "ImageSize" -> 400, "HorizontalSpacing" -> {1, 2}]
Out[5]=

ShowPercentages (1) 

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

In[6]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.0"][flows, categories, stages, "ImageSize" -> 400, "ShowPercentages" -> True]
Out[10]=

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[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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.0"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> "Groups"]
Out[12]=

With the setting "SortBySize" True, AlluvialFlowChart sorts the groups by size:

In[13]:=
ResourceFunction["AlluvialFlowChart"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> True]
Out[17]=

With the setting "SortBySize" False. AlluvialFlowChart sorts each stage by reverse categories:

In[18]:=
ResourceFunction["AlluvialFlowChart"][flows, categories, stages, "ImageSize" -> 400, "SortBySize" -> False]
Out[22]=

RibbonCurveFactor (1) 

Specify the smoothness of the ribbon curves:

In[23]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; 
ResourceFunction["AlluvialFlowChart"][flows, categories, stages, "ImageSize" -> 400, "RibbonCurveFactor" -> #] & /@ {0.1, .5, 1} // Row
Out[24]=

MinFlowThreshold (1) 

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

In[25]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; 
ResourceFunction["AlluvialFlowChart"][flows, categories, stages, "ImageSize" -> 400, "MinFlowThreshold" -> #] & /@ {1, 3, 4} // Row
Out[26]=

LabelStyle (1) 

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

In[27]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.0"][flows, categories, stages, "ImageSize" -> 400, "LabelStyle" -> Directive[FontFamily -> "Arial", FontWeight -> Italic]]
Out[31]=

ValueStyle (1) 

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

In[32]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals}; ResourceFunction["AlluvialFlowChart", ResourceVersion->"1.0.0"][flows, categories, stages, "ImageSize" -> 400, "ValueStyle" -> Directive[FontFamily -> "Arial", FontSize -> 20]]
Out[33]=

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[34]:=
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 = {(*A->{Open,Closed,
   Shared}*){0, 1, 0},(*B*){1, 1, 2},(*C*){0, 4, 1}};
flows = {employmentTotals, usageTotals};
alluvialFlowChart = ResourceFunction["AlluvialFlowChart"][flows, categories, {"A", "B", "C", "D", "E"}, "ImageSize" -> 300, "LabelStyle" -> Directive[FontFamily -> "Arial", FontWeight -> Italic]];
Row[{alluvialChart, alluvialFlowChart}]
Out[35]=

Publisher

Karl Fraser

Version History

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

Related Resources

License Information