Dumbbell graphs display the relationship between two data points for multiple categories by connecting them with a line. It effectively shows the difference or change between these two values for each item, allowing for easy comparison of magnitudes and variations across the dataset. This visualization is useful for highlighting shifts or disparities.
<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 = { "y": { "vars": ["Combined","Male","Female"], "smps": ["Monaco","Japan","Germany","Italy","Greece","Hong Kong","Austria","Spain","Netherlands","Finland","South Korea","France","Poland","United Kingdom","Russia","Norway","United States","New Zealand","China"], "data": [ [53.1,47.3,47.1,45.5,44.5,44.4,44,42.7,42.6,42.5,41.8,41.4,40.7,40.5,39.6,39.2,38.1,37.9,37.4], [51.7,46,46,44.4,43.5,43.5,42.8,41.5,41.5,40.9,40.2,39.6,39,39.3,36.6,38.4,36.8,37.1,36.5], [54.5,48.7,48.2,46.5,45.6,45,45.1,43.9,43.6,44.3,43.4,43.1,42.4,41.7,42.5,40,39.4,38.8,38.4] ] } } // Create the configuration for the graph var config = { "colors": ["grey", "blue", "pink"], "graphType": "Dumbbell", "legendColumns": 2, "legendPosition": "bottom", "sortDir": "ascending", "title": "Age Range by Gender", "xAxis": [ "Female", "Male" ], "xAxis2Show": true, "xAxisShow": false, "xAxisTitle2": "Age" } // 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-dumbbell2-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE) canvasXpress( data=y, colors=list("grey", "blue", "pink"), graphType="Dumbbell", legendColumns=2, legendPosition="bottom", sortDir="ascending", title="Age Range by Gender", xAxis=list("Female", "Male"), xAxis2Show=TRUE, xAxisShow=FALSE, xAxisTitle2="Age" )