Sankey Chart

A Sankey Diagram is a visualisation technique that allows to display flows. Several entities (nodes) are represented by rectangles or text. Their links are represented with arrows or arcs that have a width proportional to the importance of the flow. Note that an Alluvial diagram is a sub category of Sankey diagrams where nodes are grouped in vertical nodes (sometimes called steps).


Example Color Themes

Example Fonts



Show Code

Tools

<!-- Include the CanvasXpress library in your HTML file -->
<link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
<script src="https://www.canvasxpress.org/canvasXpress.min.js"></script>


<!-- Create a canvas element for the chart with the desired dimensions -->
<div>
  <canvas id="canvasId" width="600" height="600"</canvas>
</div>


<!-- Create a script to initialize the chart -->
<script>

  <!-- Create the data for the graph -->
  var data = {
     "x" : {
        "Source" : ["A","A","A","B","B","B"],
        "Target" : ["X","Y","Z","X","Y","Z"],
        "Weight" : [1,2,3,4,5,6]
     },
     "y" : {
        "data" : [
          [5,7,6,2,9,4]
        ],
        "smps" : ["smp1","smp2","smp3","smp4","smp5","smp6"],
        "vars" : ["Weight"]
     }
  }
  
  
  <-- Create the configuration for the graph -->
  var config = {
     "graphOrientation":"vertical",
     "graphType":"Sankey",
     "sankeyNodesColor":"rgba(20, 250, 50, 0.4)",
     "sankeySource":"Source",
     "sankeyTarget":"Target",
     "showTransition":"false",
     "theme":"CanvasXpress",
     "title":"Single Level Sankey"
  }
  

  <!-- Call the CanvasXpress function to create the graph -->
  var cX = new CanvasXpress("canvasId", data, config);


</script>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/cX-sankey-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
x=read.table("https://www.canvasxpress.org/data/cX-sankey-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
  data=y,
  smpAnnot=x,
  graphOrientation="vertical",
  graphType="Sankey",
  sankeyNodesColor="rgba(20, 250, 50, 0.4)",
  sankeySource="Source",
  sankeyTarget="Target",
  showTransition=FALSE,
  theme="CanvasXpress",
  title="Single Level Sankey"
)