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" : ["Brazil","Brazil","Brazil","Brazil","Canada","Canada","Canada","Mexico","Mexico","Mexico","Mexico","USA","USA","USA","USA","Portugal","Portugal","Portugal","Portugal","France","France","France","France","France","Spain","Spain","Spain","England","England","England","England","SouthAfrica","SouthAfrica","SouthAfrica","Angola","Angola","Angola","Senegal","Senegal","Senegal","Mali","Mali","Mali","Morocco","Morocco","Morocco"],
        "Target" : ["Portugal","France","Spain","England","Portugal","France","England","Portugal","France","Spain","England","Portugal","France","Spain","England","Angola","Senegal","Morocco","SouthAfrica","Angola","Senegal","Mali","Morocco","SouthAfrica","Senegal","Morocco","SouthAfrica","Angola","Senegal","Morocco","SouthAfrica","China","India","Japan","China","India","Japan","China","India","Japan","China","India","Japan","China","India","Japan"],
        "Weight" : [1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,13,13,13,13,5,5,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12]
     },
     "y" : {
        "data" : [
          [5,1,1,1,1,5,1,1,1,5,1,1,1,1,5,2,1,1,3,1,3,3,3,1,1,3,1,1,1,2,7,5,1,3,5,1,3,5,1,3,5,1,3,5,1,3]
        ],
        "smps" : ["smp1","smp2","smp3","smp4","smp5","smp6","smp7","smp8","smp9","smp10","smp11","smp12","smp13","smp14","smp15","smp16","smp17","smp18","smp19","smp20","smp21","smp22","smp23","smp24","smp25","smp26","smp27","smp28","smp29","smp30","smp31","smp32","smp33","smp34","smp35","smp36","smp37","smp38","smp39","smp40","smp41","smp42","smp43","smp44","smp45","smp46"],
        "vars" : ["Weight"]
     }
  }
  
  
  <-- Create the configuration for the graph -->
  var config = {
     "graphOrientation":"vertical",
     "graphType":"Sankey",
     "sankeySource":"Source",
     "sankeyTarget":"Target",
     "theme":"CanvasXpress",
     "title":"Multilevel 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-sankey2-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-sankey2-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",
  sankeySource="Source",
  sankeyTarget="Target",
  theme="CanvasXpress",
  title="Multilevel Sankey"
)