Scatter Plot with Compact Legend Bins
Scatter2D graphs are a fundamental visualization tool used to display the relationship between two numerical variables. Each data point is represented as a dot on a two-dimensional plane, where the x-coordinate and y-coordinate correspond to the values of the two variables. This allows for quick identification of trends, clusters, and outliers in the data. Applications range from scientific data analysis to business intelligence, making them highly versatile. Creating effective Scatter2D graphs involves careful consideration of axis scaling, labeling, and color-coding. Highlighting specific data points or regions can improve understanding. Interactive Scatter2D plots further enhance exploration, allowing users to zoom, pan, and select individual data points for detailed examination. Choosing appropriate visualization tools greatly impacts the ability to draw meaningful insights from data.
<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": "Scatter2D",
"xAxis": [
"GDP per capita"
],
"yAxis": [
"Life expectancy"
],
"sizeBy": "Population",
"title": "Income vs life expectancy",
"xAxisNumberFormat": {
"style": "currency",
"currency": "USD",
"decimals": 0
},
"legendNumberFormat": "compact",
"tooltipNumberFormat": "comma",
"citation": "legendNumberFormat: compact population bins"
}
// 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": [
"USA",
"Germany",
"Japan",
"Brazil",
"India",
"Nigeria",
"China",
"Indonesia"
],
"smps": [
"GDP per capita",
"Life expectancy"
],
"data": [
[
65000,
79
],
[
53000,
81
],
[
42000,
84
],
[
9000,
76
],
[
2100,
70
],
[
2200,
55
],
[
10500,
77
],
[
4100,
72
]
]
},
"z": {
"Population": [
331000000,
83000000,
126000000,
213000000,
1380000000,
206000000,
1440000000,
273000000
]
}
}
// Create the configuration for the graph
var config = {
"graphType": "Scatter2D",
"xAxis": [
"GDP per capita"
],
"yAxis": [
"Life expectancy"
],
"sizeBy": "Population",
"title": "Income vs life expectancy",
"xAxisNumberFormat": {
"style": "currency",
"currency": "USD",
"decimals": 0
},
"legendNumberFormat": "compact",
"tooltipNumberFormat": "comma",
"citation": "legendNumberFormat: compact population bins"
}
// 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-scatter2d24-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
z=read.table("https://www.canvasxpress.org/data/r/cX-scatter2d24-var.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
varAnnot=z,
citation="legendNumberFormat: compact population bins",
graphType="Scatter2D",
legendNumberFormat="compact",
sizeBy="Population",
title="Income vs life expectancy",
tooltipNumberFormat="comma",
xAxis=list("GDP per capita"),
xAxisNumberFormat=list(currency="USD", decimals=0, style="currency"),
yAxis=list("Life expectancy")
)
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 = "scatter2d24",
data = {
"y": {
"vars": ["USA", "Germany", "Japan", "Brazil", "India", "Nigeria", "China", "Indonesia"],
"smps": ["GDP per capita", "Life expectancy"],
"data": [
[65000, 79],
[53000, 81],
[42000, 84],
[9000, 76],
[2100, 70],
[2200, 55],
[10500, 77],
[4100, 72]
]
},
"z": {
"Population": [331000000, 83000000, 126000000, 213000000, 1380000000, 206000000, 1440000000, 273000000]
}
},
config = {
"graphType": "Scatter2D",
"xAxis": ["GDP per capita"],
"yAxis": ["Life expectancy"],
"sizeBy": "Population",
"title": "Income vs life expectancy",
"xAxisNumberFormat": {
"style": "currency",
"currency": "USD",
"decimals": 0
},
"legendNumberFormat": "compact",
"tooltipNumberFormat": "comma",
"citation": "legendNumberFormat: compact population bins"
},
width = 600,
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 = "scatter2d24",
data = {
"y": {
"vars": ["USA", "Germany", "Japan", "Brazil", "India", "Nigeria", "China", "Indonesia"],
"smps": ["GDP per capita", "Life expectancy"],
"data": [
[65000, 79],
[53000, 81],
[42000, 84],
[9000, 76],
[2100, 70],
[2200, 55],
[10500, 77],
[4100, 72]
]
},
"z": {
"Population": [331000000, 83000000, 126000000, 213000000, 1380000000, 206000000, 1440000000, 273000000]
}
},
config = {
"graphType": "Scatter2D",
"xAxis": ["GDP per capita"],
"yAxis": ["Life expectancy"],
"sizeBy": "Population",
"title": "Income vs life expectancy",
"xAxisNumberFormat": {
"style": "currency",
"currency": "USD",
"decimals": 0
},
"legendNumberFormat": "compact",
"tooltipNumberFormat": "comma",
"citation": "legendNumberFormat: compact population bins"
},
width = 600,
height = 600
)
)
using CanvasXpress
canvasxpress(Dict(
"y" => Dict(
"vars" => ["USA", "Germany", "Japan", "Brazil", "India", "Nigeria", "China", "Indonesia"],
"smps" => ["GDP per capita", "Life expectancy"],
"data" => [
[65000, 79],
[53000, 81],
[42000, 84],
[9000, 76],
[2100, 70],
[2200, 55],
[10500, 77],
[4100, 72]
]
),
"z" => Dict(
"Population" => [331000000, 83000000, 126000000, 213000000, 1380000000, 206000000, 1440000000, 273000000]
)
);
graphType = "Scatter2D",
xAxis = ["GDP per capita"],
yAxis = ["Life expectancy"],
sizeBy = "Population",
title = "Income vs life expectancy",
xAxisNumberFormat = Dict(
"style" => "currency",
"currency" => "USD",
"decimals" => 0
),
legendNumberFormat = "compact",
tooltipNumberFormat = "comma",
citation = "legendNumberFormat: compact population bins"
)























