Sankey charts are a visual method for displaying flows and transfers of data within complex systems. These charts are particularly useful for tracking the movement of resources between different entities and can be applied to a wide range of fields, including economics, energy, and environmental science. In this article, we will explore the creation and applications of Sankey charts, helping you to untangle complex systems visually.
Defining Sankey Charts
Sankey charts, named after Charles Howard Blakesley Sankey, an English engineer, are graphical representations that show the flow and transfer of data between different entities or components within a system. They consist of nodes, which represent the entities, and links, which represent the flow between these entities. Each link has a width that corresponds to the amount of data flowing between the nodes, making it easy to compare and understand the relative size of the flows.
Creating Sankey Charts
Creating a Sankey chart typically involves the following steps:
- Identifying the entities and flows within the system you want to analyze. Examples of entities can include countries, industries, or energy sources, while examples of flows can include trade, energy consumption, or waste production.
- Gathering data on the flows between the entities. This data should include the amount of data flowing from one entity to another and the direction of the flow (i.e., entity A to entity B, or vice versa).
- Organizing the data into a suitable data format for Sankey chart creation. Popular data formats include CSV, Excel, and JSON.
- Using a Sankey chart software or tool to create the chart based on your data. There are many options available, including Tableau, D3.js, and Visio. In this article, we will use the open-source library called ‘vis-network’ for demonstration purposes.
“`
import * as d3 from ‘d3’;
import * as visNetwork from ‘vis-network’;
// Sample data array
const data = [
{
id: ‘Entity 1’,
groupId: ‘Group 1’,
inEdges: [{ id: ‘Flow 1’, flowSize: 10 }],
outEdges: [{ id: ‘Flow 2’, flowSize: 20 }],
size: 5
},
{
id: ‘Entity 2’,
groupId: ‘Group 2’,
inEdges: [{ id: ‘Flow 3’, flowSize: 15 }],
outEdges: [{ id: ‘Flow 4’, flowSize: 30 }],
size: 10
},
// more entities and edges…
];
// Configure Sankey chart settings
const width = 600;
const height = 400;
const nodeRadius = 10;
const linkViscosity = 80;
const nodeDistance = 100;
const layoutIter = 10;
const linksStyle = { width: 2 };
// Create Sankey chart
const network = new visNetwork(document.getElementById(‘chartContainer’));
network.setData({
nodes: data.map((entity) => ({
id: entity.id,
label: entity.id,
size: entity.size,
group: Number(entity.groupId),
color: { highlight: { edges: { fill: ‘#e33a39’, ‘stroke-width’: 3 } } },
})),
edges: data.flatMap((entity) => entity.outEdges.map(({ id }) => ({
id: id,
source: entity.id,
target: data[id].id,
smooth: false,
color: { highlight: { fill: ‘#e33a39’ } },
style: linksStyle,
width: entity.flowSize,
})),
});
network.fitView();
“`
This code creates a simple Sankey chart based on our sample data array. It defines the width, height, and layout of the chart and creates the chart using the ‘vis-network’ library. To customize the chart further, you can explore various options and configurations available in the ‘vis-network’ documentation.
Applications of Sankey Charts
Sankey charts are applied in numerous fields, offering valuable insights into complex systems. Some of the most common applications include:
- Economics: Visualizing trade relationships between countries or industries, analyzing the flow of goods and services, or understanding the global economy.
- Energy: Displaying the distribution and consumption of various energy sources within an electrical grid, tracking energy production from renewable sources, or analyzing the flow of energy between countries.
- Environmental science: Comparing the recycling and waste production processes within an ecosystem or assessing the flow of resources between different environmental systems.
- Social sciences: Examining the flow of information, resources, or influence between different social groups or organizations.
- Business: Analyzing market share, customer journey, or supply chain flow within a business or industry.
To illustrate their use, let’s take a look at an energy consumption example using the ‘vis-network’ library and the following sample dataset:
const sampleData = [
{
id: 'Country 1',
groupId: 1,
inEdges: [
{ id: 'Energy Source 1 - Flow 1', flowSize: 10, type: 'import' },
{ id: 'Energy Source 2 - Flow 1', flowSize: 8, type: 'import' },
],
outEdges: [
{
id: 'Electricity Grid Flow 1 - Internal Consumption',
flowSize: 6, // Internal Consumption
type: 'consumption',
},
{
id: 'Electricity Grid Flow 1 - Consumption by Industry A',
flowSize: 2,
type: 'consumption',
},
{
id: 'Electricity Grid Flow 1 - Export to Country 2',
flowSize: 1,
type: 'export',
},
],
size: 5
},
{
id: 'Country 2',
groupId: 2, ...
This sample dataset contains data about energy flowing between countries, energy sources, and internal consumption. By using a Sankey chart, you can easily visualize and understand the energy flow within this system. This allows you to identify potential bottlenecks, inefficiencies, or opportunities for improvement.
Final Thoughts
Sankey charts offer an effective means of visualizing and understanding complex systems by representing the flow and transfer of data between entities. By following the creation steps and exploring various applications, you can unlock valuable insights and uncover trends within your data. Additionally, various open-source libraries and tools, like ‘vis-network’, make it easy to create custom Sankey charts that cater to your specific needs. So, the next time you encounter a daunting dataset or need to untangle a complicated system, consider employing Sankey charts to gain a clearer picture and make more informed decisions.
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.