A tree graph is a network structure. It is constituted of a root node that gives birth to several nodes connected by edges or branches.
<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" : { "Annot1" : ["A","B","C","A","B","C","A","B","C","A","B","C","A","B","C","A"], "Annot2" : [5,10,15,20,25,30,35,40,40,35,30,25,20,15,10,5], "Level1" : ["L1.1","L1.1","L1.1","L1.1","L1.2","L1.2","L1.2","L1.2","L1.3","L1.3","L1.3","L1.3","L1.4","L1.4","L1.4","L1.4"], "Level2" : ["L2.1","L2.1","L2.2","L2.2","L2.1","L2.1","L2.2","L2.2","L2.1","L2.1","L2.2","L2.2","L2.1","L2.1","L2.2","L2.2"], "Level3" : ["L3.1","L3.2","L3.1","L3.2","L3.1","L3.2","L3.1","L3.2","L3.1","L3.2","L3.1","L3.2","L3.1","L3.2","L3.1","L3.2"] }, "y" : { "data" : [ [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] ], "smps" : ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"], "vars" : ["Order"] } } // Create the configuration for the graph var config = { "colorBy":"Annot1", "graphType":"Tree", "hierarchy":[ "Level1", "Level2", "Level3" ], "legendKeyBackgroundBorderColor":"rgba(255,255,255,0)", "legendKeyBackgroundColor":"rgba(255,255,255,0)", "showTransition":true, "title":"Collapsible Tree" } // Call the CanvasXpress function to create the graph var cX = new CanvasXpress("canvasId", data, config); </script> </body>
library(canvasXpress) y=read.table("https://www.canvasxpress.org/data/cX-tree-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-tree-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE) canvasXpress( data=y, smpAnnot=x, colorBy="Annot1", graphType="Tree", hierarchy=list("Level1", "Level2", "Level3"), legendKeyBackgroundBorderColor="rgba(255,255,255,0)", legendKeyBackgroundColor="rgba(255,255,255,0)", showTransition=TRUE, title="Collapsible Tree" )