Unleashing the Power of Sankey Charts: Visualizing Flows Like Never Before

Sankey charts are a powerful tool for visualizing flows and relationships between different entities. They are named after Captain Matthew Henry Phineas Barnum, who developed them in the 19th century to represent his family’s income sources. Since then, sankey charts have become popular in various fields, including science, economics, and social sciences, due to their ability to show the flow of resources, data, or energy in a clear and intuitive way.

In this article, we will explore what sankey charts are, how to create them, and their various applications across different industries.

What are Sankey Charts?

Sankey charts are a type of flow diagram where the width of the arrows (also known as pipes or bands) represents the magnitude of the flow between different entities. This makes it an excellent tool for visualizing the distribution and movement of resources, such as data, energy, or material throughout a system.

In the simplest form, a sankey diagram features three elements:

  1. Sources: The starting point of the flow, which emits a certain amount of material or data.
  2. Paths or Transfers: The lines that represent the connection between the sources and destinations. The thickness of these lines corresponds to the volume of flow or the amount transferred between entities.
  3. Sinks: The end destination of the flow, where material or data is consumed, stored, or transformed.

Sankey charts excel in showing how a total amount is divided among several parts, allowing viewers to easily spot the largest flows, identify bottlenecks or dead-ends, and perceive how the distribution changes over time or across different categories.

How to Create a Sankey Chart

Creating a sankey chart can be done using various software tools, including Excel, Tableau, Power BI, Tableau, and specialized libraries for Python and R. Here’s a general workflow for creating a sankey chart using Python with the plotly library, which also supports a more interactive and dynamic visual experience:

Step 1: Prepare Your Data

First, you need a dataset that includes the following information:

  • Source Names: Identifiers for the starting points of the flow.
  • Destination Names: Identifiers for the end points of the flow.
  • Values or Weights: The volume or quantity of the flow between each source and destination.
  • Optional: Labels, Grouping, or Custom Colors: To enhance the readability and aesthetics of the chart.

Here’s an example dataset:

“`python
import pandas as pd

Sample data

data = {
‘source’: [‘S1’, ‘S1’, ‘S2’, ‘S2’, ‘S3’],
‘destination’: [‘D1’, ‘D2’, ‘D1’, ‘D2’, ‘D3’],
‘value’: [40, 30, 45, 25, 60],
‘label’: [‘S’, ‘D’],
‘group’: [‘A’, ‘B’, ‘A’, ‘B’, ‘C’],
‘color’: [‘red’, ‘blue’, ‘red’, ‘blue’, ‘green’]
}
df_sankey = pd.DataFrame(data)
“`

Step 2: Encode Data as JSON

Next, you need to encode this data into a format that plotly can use to create the chart:

“`python
import json

Convert DataFrame to a format plotly can use for sankey chart

data = dfsankey.todict(orient=’records’)

source = data[‘source’]
destination = data[‘destination’]
value = data[‘value’]
labels = data[‘label’]
group = data[‘group’]
color = data[‘color’]

sankeydata = {
“nodes”: [
{“pad”: 16, “label”: labels, “color”: color}
],
“links”: [
{“source”: source, “target”: destination, “value”: value} if group == ‘A’ else {“source”: source, “target”: destination, “value”: 2 * value},
{“source”: source, “target”: destination, “value”: value} if group == ‘B’ else {“source”: source, “target”: destination, “value”: 2 * value},
{“source”: source, “target”: destination, “value”: value} if group == ‘C’ else {“source”: source, “target”: destination, “value”: 2 * value}
],
“color”: color,
“node”: [
{“pad”: 16, “label”: labels, “color”: color}
]
}
sankey
datastr = json.dumps(sankeydata)
print(json.dumps(sankey_data, indent=4))
“`

Step 3: Create and Display the Sankey Chart

Now that you have the data in the correct format, you can use plotly to visualize it:

“`python
import plotly.graph_objects as go

trace = go.Sankey(
valueformat = ‘,’,
valuesuffix = ‘ Kb’,
node = {“pad”: 16, “label”: labels, “color”: color},
link = {“source”: [int(n) for n in source], “target”: [int(n) for n in destination], “value”: value},
)

layout = go.Layout(
title = “Sankey Figure”,
font = dict(size=10),
)

fig = go.Figure(data=[trace], layout=layout)
fig.show()
“`

These steps will generate an interactive sankey chart with different data points, labels, and colors, allowing for a clear visualization of the flows between entities.

Applications of Sankey Charts

Sankey charts are used across various industries for a multitude of purposes, some of which include:

  1. Energy Management: To show the flow of energy production, consumption, and distribution.
  2. Business Analytics: For analyzing sales pipelines, supply chain flows, and customer journey maps.
  3. Social Sciences: Visualizing social networks, public health statistics, and demographic trends.
  4. Environmental Science: Mapping the flow of resources like water or carbon emissions between different regions or systems.
  5. Economics: Illustrating trade relationships, employment trends, or financial flows between countries.

By leveraging sankey charts, organizations can gain insights into the intricate movements of resources within their systems, make data-driven decisions, and communicate complex information in a visually engaging manner.

Sankey charts are a versatile tool that empowers professionals in various fields to present and analyze flows more effectively than traditional chart types. Whether it’s visualizing energy systems, supply chains, economic networks, or social dynamics, sankey diagrams provide a clear, intuitive, and comprehensive way to understand the flow of resources throughout a given system.

SankeyMaster

SankeyMaster is your go-to tool for creating complex Sankey charts . Easily enter data and create Sankey charts that accurately reveal intricate data relationships.

SankeyMaster - Unleash the Power of Sankey Diagrams on iOS and macOS.
SankeyMaster is your essential tool for crafting sophisticated Sankey diagrams on both iOS and macOS. Effortlessly input data and create intricate Sankey diagrams that unveil complex data relationships with precision.
SankeyMaster - Unleash the Power of Sankey Diagrams on iOS and macOS.
SankeyMaster is your essential tool for crafting sophisticated Sankey diagrams on both iOS and macOS. Effortlessly input data and create intricate Sankey diagrams that unveil complex data relationships with precision.