Sankey Diagrams
By: Darío Weitz
Tags: Storytelling, Data Visualization, Charts, Data Science, Sankey Diagram

Sankey Diagrams

Why & How, Storytelling with Sankey

Image by Mike Lewis from Unsplash

Captain Matthew Henry Phineas Riall Sankey was a brilliant Irish engineer who lived from 1853 to 1925. After completing his university studies at the School of Military Engineering in Chatham, United Kingdom, he began working in the British War Office in architectural design. In 1889 he left the military activity to move to the company Willans and Robinson as a chief engineer and designer of steam engines. There he conducted a series of important experiments related to improvements in the efficiency of the machines manufactured by the company. The emphasis was on understanding where and how energy flows were distributed so that improvements could be made to increase the overall efficiency of the machines.

In Captain Sankey’s words: “No portion of a steam plant is perfect, and each is the seat of losses more or less serious. If therefore it is desired to improve the steam plant as a whole, it is first of all necessary to ascertain separately the nature of the losses due to its various portions; and in this connection the diagrams in Plate 5 have been prepared, which it is hoped may assist to a clearer understanding of the nature and extent of the various losses.”

The quote refers to a diagram invented by the captain in 1898 to visualize the energy flows in the steam engines that he studied in absolute detail. Figure 1 reproduces the original diagram of 1898. The diagram was forgotten until it was recovered at the beginning of the 20th century by the Austrian mechanical engineer Alois Riedler (1850–1936) to study the energy flows in the first passenger vehicles. Captain Sankey’s original ideas were again recovered when the extraordinary advance in hardware and software allowed Data Visualization developers to generate improved and sophisticated versions of the Sankey Diagrams.

Fig.1: original diagram invented by Captain Sankey

WHY: Flowcharts are widely used in many technical and non-technical fields to study, improve, and communicate complex processes through simple and clear diagrams. Sankey Diagrams are a specific type of flow diagrams characterized by the presence of nodes linked by directed arrows representing flows of the process under study. The width of the arrows represents the amount of material, energy, or other resource that makes up the flow that circulates through the system. The direction of the arrows indicates the flow from one node to the next in the diagram. The flows can be combined, separated, or tracked through a series of stages represented by the nodes.

Historically, Sankey Diagrams were used to represent energy flows but over the years new applications have been added: process flow; material flow; natural resources flow; logistics and transportation of goods; supply chains; cost flow; web page information flow; population migration; market analysis. In summary, they are used to visually represent the physical flow of objects or resources associated with a process or system.

HOW: To date, there is no standardized version of the Sankey Diagrams: which is why there are different designs and arrangements. What can’t be missing are the directed arrows with their width proportional to the magnitude of the flow they are representing.

The arrows are drawn between two nodes, one of which represents the origin, source, or outlet of the flow while the other node represents the destination or sink. The diagrams can have a horizontal or vertical orientation, but they are generally represented from left to right, or from top to bottom. They usually have different colors to indicate different materials or different dimensions.

Fig.2: schematic representation of a Sankey Diagram: nodes in blue, links in other colors. Diagram made by the author with Plotly.

Sankey Diagrams allow reducing complex systems into relatively simple diagrams where the main flows with their corresponding interactions can be seen. They help to locate the dominant contributions in the total flow. They excel in the analysis of dynamic systems by allowing easy visualization of the flows and stocks that make up the system.

Some Warnings

Be careful with the indiscriminate use of Sankey Diagrams: the storytelling becomes confusing with the increase in the number of nodes and crossovers.

Audiences are often not familiar with these types of charts. Always take some time to explain to the audience the particular characteristics of them so as not to impair the storytelling.

Comparison between nodes is difficult when the width of the nodes is relatively similar. If the main objective is to make some kind of comparison, it may be convenient to replace them with another type of diagram that allows a better visualization (e.g.: bar chart).

A shortcoming of many commercial tools is the impossibility of feedback from an output stream to a previous stage or process. Nowadays it is very common to recover part of the heat or energy and reinject it into the system to improve its efficiency, or to recycle materials to reduce pollution. Not all the visualization tools have the alternative of feedback or recycling in their Sankey functions.

Sankey Diagrams should not be confused with Alluvial Diagrams. As indicated by Wikipedia: “Alluvial diagrams are a type of flow diagram originally developed to represent changes in network structure over time. In allusion to both their visual appearance and their emphasis on flow, alluvial diagrams are named after alluvial fans that are naturally formed by the soil deposited from streaming water“[1]. Alluvial diagrams are used to show how elements of a population are related across different categorical dimensions and where the location of nodes has no particular meaning. Alluvial diagrams will be the subject of a future article.

Examples

- Eurostat is the European Union’s statistical office and its mission is to provide quality statistics and data on the countries and regions that make up the aforementioned Union. Eurostat developed a visualization tool for the generation of Sankey Diagrams for material flows (Fig.3). A second tool allows the visualization of energy flows for the different countries of the Union (Fig. 4). These are interactive diagrams with a lot of additional information [2]. A recycling stream can be seen in Figure 3.

Fig.3: Sankey Diagram for Material Flow. Source: Eurostat, [2].

Fig.4: Sankey Diagram for Energy Flow. Source: Eurostat, [2].

2.- The International Energy Agency (IEA) completed a project that resulted in an Interactive Sankey Diagram showing energy data for 140 countries since 1973. The diagram makes it possible to visualize energy transfers at the global, regional (OECD, European Union, African Union) or individual country level. Fig. 5 shows the balance of energy flows from production, imports, exports, losses, and consumption in the Argentine Republic for the year 2018 [3]. It is clear that a Sankey diagram is the most appropriate visualization technique to show this kind of information.

Fig.5: Sankey Diagram for Argentina. Source: IEA, [3].

Software

Matplotlib has a Sankey class ( from matplotlib.sankey import Sankey ) [4]. To generate the diagram you have to supply numerical values to the arguments flows, labels, orientations, and pathlengths . The values of the argument flows indicate the sizes of the flows, with positive values for the inputs and negative values for the outputs. The argument orientations can only take the values 1 for from/to the top, 0 for from/to the right or left, -1 for from/to the bottom. The pathlengths argument is a list of the lengths of the vertical arrows. There is also a rotation argument to orient the diagram in a different direction than the horizontal default.

Plotly Python Open Source Graphing Library makes Sankey Diagrams [5]. You have to provide values for the following parameters: source representing the source nodes, target for the target nodes, value for the flow quantities, and label for the name of the nodes. The visualization is significantly improved with the use of colored links (Fig.2).

e!Sankey is a visualization tool specialized in the drawing of Sankey Diagrams. Developed by the company ifu hamburg, Member of iPoint Group, provides all the necessary elements to visualize energy and material flows with different alternatives for the design of the final diagram. The steps for the drawing of the diagram are relatively intuitive and it has a generator of process operations that allows adding, mixing, subtracting, and separating the flows that circulate through arrows and preset nodes. As usual, you can download a trial version to practice all the functions provided by the tool.

Summarizing

The key concept in a Diagram Sankey is the amount of flow moving from one node to another. In this sense, the width of the arrows and the location of the nodes are of fundamental importance. Despite being relatively complex to implement and visualize, their use is expected to increase considerably in the coming years.

If you find this article of interest, please read my previous (https://medium.com/@dar.wtz):

Diverging Bars, Why & How, Storytelling with Divergences

Slope Charts, Why & How, Storytelling with Slopes

References

[1]: https://en.wikipedia.org/wiki/Alluvial_diagram

[2]: https://ec.europa.eu/eurostat/help/first-visit/tools

[3]: https://www.iea.org/sankey/#?c=Argentina&s=Balance

[4]: https://matplotlib.org/3.1.1/api/sankey_api.html

[5]: https://plotly.com/python/sankey-diagram/