Sankey diagrams provide a clear visual representation of flows and are used across various fields, from energy systems to financial analysis. Their strength lies in showing the magnitude of flows between different stages or categories, making complex relationships easy to understand. These diagrams are particularly useful for highlighting bottlenecks or inefficiencies in a process. They are easily created using various software and readily interpretable, making them an excellent communication tool for complex data visualization.
<html> <head> <!-- 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/dist/canvasXpress.min.js"></script> </head> <body> <!-- 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 = { "colorBy" : "Weight", "graphOrientation" : "vertical", "graphType" : "Sankey", "sankeySource" : "Source", "sankeyTarget" : "Target", "title" : "Multilevel Sankey", "xAxis" : ["Weight"] } // Event used to create graph (optional) var events = false // Call the CanvasXpress function to create the graph var cX = new CanvasXpress("canvasId", data, config, events); </script> </body> </html>
library(canvasXpress) y=read.table("https://www.canvasxpress.org/data/r/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/r/cX-sankey2-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE) canvasXpress( data=y, smpAnnot=x, colorBy="Weight", graphOrientation="vertical", graphType="Sankey", sankeySource="Source", sankeyTarget="Target", title="Multilevel Sankey", xAxis=list("Weight") )