Sankey flow diagrams

Updated at January 6th, 2020

Sankey diagrams are sometimes useful to show the relationship between discrete variables. Applications include progression of therapy, customer conversion, or almost any crosstab. Here's how to create and customize them in Protobi. 

The above chart shows the relationship between two discrete questions, Q1(happiness) and Q1 (health).

Flow diagrams from crosstabs

Below are these two questions shown as marginal distributions:

We can create a crosstab by dragging one element onto another (see brief video): 

Press the circle edit icon and from the context menu choose "Chart type..." and select "Sankey": 

The graph should now look like the one at top of this page. Colors are assigned by default, but you can override them by specifying colors, see below.

Flow diagrams from groups

You may have a sequence of variables, like first-, second- and third-line therapy. You can create a Sankey flow diagram directly from any collection of discrete variables. The order of columns in the diagram is the order of elements in the group.

Here we created a special group of Q1 (happiness), Q2 (health) and Q3 (wealth):

Setting the chart type to Sankey creates a diagram as follows: 

Customize colors

If the overall chart has a format specified, colors will be assigned by default. Otherwise, colors will appear all black initially:

You can set specific colors from the context menu for the chart element. Choose "Edit JSON..." and create a "colors" attribute. This should be an object mapping (unformatted) values to HTML colors like below: 

Customize positions

The boxes are positioned by default to minimize line crossings. You can customize box positions by dragging them up or down.

The positions you drag are saved, the rest are free. Since the graph is redrawn on every press, it's often best to position everything if you position anything. Although sometimes it's sufficient to move special categories like "Other" down to the bottom and leave the others free to move.

Customize size

To change the size or margin of the graph, select the chart element by pressing on the header. Blue resize handles and red margin handles will appear. You can drag these with the mouse or set them explicitly under "Edit JSON..." by setting the "size"and "margin" attributes under "chartOptions":

Was this article helpful?