Timespan ranges with dots and direct labels
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>
// Use a data frame (2D-array) for the graph
var data =
// Create the configuration for the graph
var config = {
"graphType" : "Dumbbell",
"dumbbellType" : "connected",
"theme" : "paulTol",
"colorScheme" : "User",
"colors" : [
"#332288",
"#332288"
],
"title" : "From pathogen to vaccine",
"subtitle" : "Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
"xAxis" : [
"Pathogen identified",
"Vaccine licensed"
],
"xAxisTitle" : "Year",
"setMinX" : 1860,
"setMaxX" : 2040,
"xAxisTickFormat" : "%.0f",
"sortDir" : "ascending",
"showLegend" : false,
"dataPointSizeScaleFactor" : 2.2,
"citation" : "Source: synthetic data for illustration"
}
// 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>
<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" : [
"Pathogen identified",
"Vaccine licensed"
],
"smps" : [
"Cholera",
"Tuberculosis",
"Malaria",
"Dengue",
"Anthrax",
"Rabies",
"Hepatitis A",
"Mumps",
"HPV",
"Ebola"
],
"data" : [
[
1883,
1882,
1880,
1943,
1876,
1885,
1973,
1934,
1983,
1976
],
[
1991,
1921,
2021,
2019,
1881,
1885,
1995,
1967,
2006,
2019
]
]
}
}
// Create the configuration for the graph
var config = {
"graphType" : "Dumbbell",
"dumbbellType" : "connected",
"theme" : "paulTol",
"colorScheme" : "User",
"colors" : [
"#332288",
"#332288"
],
"title" : "From pathogen to vaccine",
"subtitle" : "Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
"xAxis" : [
"Pathogen identified",
"Vaccine licensed"
],
"xAxisTitle" : "Year",
"setMinX" : 1860,
"setMaxX" : 2040,
"xAxisTickFormat" : "%.0f",
"sortDir" : "ascending",
"showLegend" : false,
"dataPointSizeScaleFactor" : 2.2,
"citation" : "Source: synthetic data for illustration"
}
// 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-dumbbell13-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
citation="Source: synthetic data for illustration",
colorScheme="User",
colors=list("#332288", "#332288"),
dataPointSizeScaleFactor=2.2,
dumbbellType="connected",
graphType="Dumbbell",
setMaxX=2040,
setMinX=1860,
showLegend=FALSE,
sortDir="ascending",
subtitle="Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
theme="paulTol",
title="From pathogen to vaccine",
xAxis=list("Pathogen identified", "Vaccine licensed"),
xAxisTickFormat="%.0f",
xAxisTitle="Year"
)
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import show_in_browser
if __name__ == "__main__":
# Define the chart with its data and configuration
chart: CanvasXpress = CanvasXpress(
render_to = "dumbbell13",
data = {
"y": {
"vars": ["Pathogen identified", "Vaccine licensed"],
"smps": ["Cholera", "Tuberculosis", "Malaria", "Dengue", "Anthrax", "Rabies", "Hepatitis A", "Mumps", "HPV", "Ebola"],
"data": [
[1883, 1882, 1880, 1943, 1876, 1885, 1973, 1934, 1983, 1976],
[1991, 1921, 2021, 2019, 1881, 1885, 1995, 1967, 2006, 2019]
]
}
},
config = {
"graphType": "Dumbbell",
"dumbbellType": "connected",
"theme": "paulTol",
"colorScheme": "User",
"colors": ["#332288", "#332288"],
"title": "From pathogen to vaccine",
"subtitle": "Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
"xAxis": ["Pathogen identified", "Vaccine licensed"],
"xAxisTitle": "Year",
"setMinX": 1860,
"setMaxX": 2040,
"xAxisTickFormat": "%.0f",
"sortDir": "ascending",
"showLegend": False,
"dataPointSizeScaleFactor": 2.2,
"citation": "Source: synthetic data for illustration"
},
width = 760,
height = 480
)
# Display the chart in its own Web page
show_in_browser(chart)
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import graph
graph(
CanvasXpress(
render_to = "dumbbell13",
data = {
"y": {
"vars": ["Pathogen identified", "Vaccine licensed"],
"smps": ["Cholera", "Tuberculosis", "Malaria", "Dengue", "Anthrax", "Rabies", "Hepatitis A", "Mumps", "HPV", "Ebola"],
"data": [
[1883, 1882, 1880, 1943, 1876, 1885, 1973, 1934, 1983, 1976],
[1991, 1921, 2021, 2019, 1881, 1885, 1995, 1967, 2006, 2019]
]
}
},
config = {
"graphType": "Dumbbell",
"dumbbellType": "connected",
"theme": "paulTol",
"colorScheme": "User",
"colors": ["#332288", "#332288"],
"title": "From pathogen to vaccine",
"subtitle": "Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
"xAxis": ["Pathogen identified", "Vaccine licensed"],
"xAxisTitle": "Year",
"setMinX": 1860,
"setMaxX": 2040,
"xAxisTickFormat": "%.0f",
"sortDir": "ascending",
"showLegend": False,
"dataPointSizeScaleFactor": 2.2,
"citation": "Source: synthetic data for illustration"
},
width = 760,
height = 480
)
)
using CanvasXpress
canvasxpress(Dict(
"y" => Dict(
"vars" => ["Pathogen identified", "Vaccine licensed"],
"smps" => ["Cholera", "Tuberculosis", "Malaria", "Dengue", "Anthrax", "Rabies", "Hepatitis A", "Mumps", "HPV", "Ebola"],
"data" => [
[1883, 1882, 1880, 1943, 1876, 1885, 1973, 1934, 1983, 1976],
[1991, 1921, 2021, 2019, 1881, 1885, 1995, 1967, 2006, 2019]
]
)
);
graphType = "Dumbbell",
dumbbellType = "connected",
theme = "paulTol",
colorScheme = "User",
colors = ["#332288", "#332288"],
title = "From pathogen to vaccine",
subtitle = "Year the cause of ten diseases was identified and the year a vaccine against it was licensed",
xAxis = ["Pathogen identified", "Vaccine licensed"],
xAxisTitle = "Year",
setMinX = 1860,
setMaxX = 2040,
xAxisTickFormat = "%.0f",
sortDir = "ascending",
showLegend = false,
dataPointSizeScaleFactor = 2.2,
citation = "Source: synthetic data for illustration"
)
















