Sub-national regions choropleth
Maps in CanvasXpress allow users to create interactive and customizable visualizations for geographical data. You can integrate various map types, such as choropleths or point maps, and layer your data to highlight trends, distributions, or relationships across regions. With its flexibility, Maps in CanvasXpress support detailed analysis and presentation of spatial data for a wide range of applications.
<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" : "Map",
"topoJSON" : "https://www.canvasxpress.org/data/maps/NAM.json",
"mapId" : "namibia",
"mapConfig" : {
"zoom" : 5.6,
"center" : [
-22.9,
18.5
]
},
"theme" : "bw",
"colorBy" : "Rainfall (mm)",
"colorScheme" : "User",
"colorSpectrum" : [
"#dfc27d",
"#a6b37a",
"#35978f",
"#01665e"
],
"showMapLabels" : true,
"title" : "Annual rainfall per region",
"subtitle" : "Regional mean of total yearly rainfall in mm (synthetic)",
"legendPosition" : "topRight",
"showLegendTitle" : true,
"mapOutlineColor" : "#ffffff",
"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" : [
"Karas",
"Kunene",
"Omusati",
"Ohangwena",
"Kavango",
"Caprivi",
"Hardap",
"Otjozondjupa",
"Omaheke",
"Erongo",
"Khomas",
"Oshana",
"Oshikoto"
],
"smps" : [
"Rainfall (mm)"
],
"data" : [
[
70
],
[
120
],
[
330
],
[
410
],
[
520
],
[
660
],
[
160
],
[
440
],
[
360
],
[
60
],
[
300
],
[
350
],
[
400
]
]
}
}
// Create the configuration for the graph
var config = {
"graphType" : "Map",
"topoJSON" : "https://www.canvasxpress.org/data/maps/NAM.json",
"mapId" : "namibia",
"mapConfig" : {
"zoom" : 5.6,
"center" : [
-22.9,
18.5
]
},
"theme" : "bw",
"colorBy" : "Rainfall (mm)",
"colorScheme" : "User",
"colorSpectrum" : [
"#dfc27d",
"#a6b37a",
"#35978f",
"#01665e"
],
"showMapLabels" : true,
"title" : "Annual rainfall per region",
"subtitle" : "Regional mean of total yearly rainfall in mm (synthetic)",
"legendPosition" : "topRight",
"showLegendTitle" : true,
"mapOutlineColor" : "#ffffff",
"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-map24-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
colorBy="Rainfall (mm)",
colorScheme="User",
colorSpectrum=list("#dfc27d", "#a6b37a", "#35978f", "#01665e"),
graphType="Map",
legendPosition="topRight",
mapConfig=list(center=list(-22.9, 18.5), zoom=5.6),
mapId="namibia",
mapOutlineColor="#ffffff",
showLegendTitle=TRUE,
showMapLabels=TRUE,
source="Synthetic data for illustration",
subtitle="Regional mean of total yearly rainfall in mm (synthetic)",
theme="bw",
title="Annual rainfall per region",
topoJSON="https://www.canvasxpress.org/data/maps/NAM.json"
)
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 = "map23",
data = {
"y": {
"vars": ["Karas", "Kunene", "Omusati", "Ohangwena", "Kavango", "Caprivi", "Hardap", "Otjozondjupa", "Omaheke", "Erongo", "Khomas", "Oshana", "Oshikoto"],
"smps": ["Rainfall (mm)"],
"data": [
[70],
[120],
[330],
[410],
[520],
[660],
[160],
[440],
[360],
[60],
[300],
[350],
[400]
]
}
},
config = {
"graphType": "Map",
"topoJSON": "https://www.canvasxpress.org/data/maps/NAM.json",
"mapId": "namibia",
"mapConfig": {
"zoom": 5.6,
"center": [-22.9, 18.5]
},
"theme": "bw",
"colorBy": "Rainfall (mm)",
"colorScheme": "User",
"colorSpectrum": ["#dfc27d", "#a6b37a", "#35978f", "#01665e"],
"showMapLabels": True,
"title": "Annual rainfall per region",
"subtitle": "Regional mean of total yearly rainfall in mm (synthetic)",
"legendPosition": "topRight",
"showLegendTitle": True,
"mapOutlineColor": "#ffffff",
"source": "Synthetic data for illustration"
},
width = 760,
height = 600
)
# 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 = "map23",
data = {
"y": {
"vars": ["Karas", "Kunene", "Omusati", "Ohangwena", "Kavango", "Caprivi", "Hardap", "Otjozondjupa", "Omaheke", "Erongo", "Khomas", "Oshana", "Oshikoto"],
"smps": ["Rainfall (mm)"],
"data": [
[70],
[120],
[330],
[410],
[520],
[660],
[160],
[440],
[360],
[60],
[300],
[350],
[400]
]
}
},
config = {
"graphType": "Map",
"topoJSON": "https://www.canvasxpress.org/data/maps/NAM.json",
"mapId": "namibia",
"mapConfig": {
"zoom": 5.6,
"center": [-22.9, 18.5]
},
"theme": "bw",
"colorBy": "Rainfall (mm)",
"colorScheme": "User",
"colorSpectrum": ["#dfc27d", "#a6b37a", "#35978f", "#01665e"],
"showMapLabels": True,
"title": "Annual rainfall per region",
"subtitle": "Regional mean of total yearly rainfall in mm (synthetic)",
"legendPosition": "topRight",
"showLegendTitle": True,
"mapOutlineColor": "#ffffff",
"source": "Synthetic data for illustration"
},
width = 760,
height = 600
)
)
using CanvasXpress
canvasxpress(Dict(
"y" => Dict(
"vars" => ["Karas", "Kunene", "Omusati", "Ohangwena", "Kavango", "Caprivi", "Hardap", "Otjozondjupa", "Omaheke", "Erongo", "Khomas", "Oshana", "Oshikoto"],
"smps" => ["Rainfall (mm)"],
"data" => [
[70],
[120],
[330],
[410],
[520],
[660],
[160],
[440],
[360],
[60],
[300],
[350],
[400]
]
)
);
graphType = "Map",
topoJSON = "https://www.canvasxpress.org/data/maps/NAM.json",
mapId = "namibia",
mapConfig = Dict(
"zoom" => 5.6,
"center" => [-22.9, 18.5]
),
theme = "bw",
colorBy = "Rainfall (mm)",
colorScheme = "User",
colorSpectrum = ["#dfc27d", "#a6b37a", "#35978f", "#01665e"],
showMapLabels = true,
title = "Annual rainfall per region",
subtitle = "Regional mean of total yearly rainfall in mm (synthetic)",
legendPosition = "topRight",
showLegendTitle = true,
mapOutlineColor = "#ffffff",
source = "Synthetic data for illustration"
)


























