CodePen
Sandbox Download

Relationship between average U.S. SAT scores and earnings.

What is a scatterplot?

Scatterplots are used to display the relationship between two numeric variables. The x-axis typically represents one numeric variable, while the y-axis represents another numeric variable.

Data configurations

This section covers a few data configuration examples for scatterplots, each configured using the scatterplot model. See the scatterplot model reference for the full list of available properties and methods.

With numeric fields

With two numeric fields, one specified via the xAxisField property and the other specified via the yAxisField property, a basic scatterplot can visualize the relationship between these two variables. Each point on the chart represents a data record, with its position determined by the values of the x and y fields.

CodePen
Sandbox Download
This chart visualizes the relationship between average SAT scores and earnings, with each point representing a data record. The x-axis represents the average SAT scores, while the y-axis represents the corresponding earnings.
  1. Set the xAxisField property to "SAT_Score_Average" and the yAxisField property to "Earnings", which are both integer fields.
With numeric fields
29 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Scatterplot</title>
<style>
html,
body,
arcgis-chart {
height: 100%;
margin: 0;
}
</style>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
</head>
<body>
<arcgis-chart></arcgis-chart>
<script type="module">
const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js");
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
const featureLayer = new FeatureLayer({
portalItem: {
id: "fcf794778a4d486eb0ce863ab71d40db",
},
});
const chartElement = document.querySelector("arcgis-chart");
const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" });
scatterplotModel.xAxisField = "SAT_Score_Average";
scatterplotModel.yAxisField = "Earnings";
5 collapsed lines
chartElement.model = scatterplotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

Customization options

Bubble plot

Scatterplot can also be configured with a third numeric field, or commonly known as a bubble plot. Allowing you to to visualize the size of each point based on the values of the third field.

CodePen
Sandbox Download
This chart visualizes the relationship between average SAT scores and earnings, with the size of each point representing the tuition fee for each average SAT score. The x-axis represents the average SAT scores, while the y-axis represents the corresponding earnings.
  1. Set the sizePolicy property to an object with type set to "sizeScale", scaleType set to "linear", field set to "TUITIONFEE", and specify the minSize and maxSize for the points.
Bubble plot
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Bubble plot</title>
<style>
html,
body,
arcgis-chart {
height: 100%;
margin: 0;
}
</style>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
</head>
<body>
<arcgis-chart></arcgis-chart>
<script type="module">
const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js");
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
const featureLayer = new FeatureLayer({
portalItem: {
id: "fcf794778a4d486eb0ce863ab71d40db",
},
});
const chartElement = document.querySelector("arcgis-chart");
const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" });
scatterplotModel.xAxisField = "SAT_Score_Average";
scatterplotModel.yAxisField = "Earnings";
scatterplotModel.sizePolicy = {
type: "sizeScale",
scaleType: "linear",
field: "TUITIONFEE",
minSize: 5,
maxSize: 20,
};
5 collapsed lines
chartElement.model = scatterplotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

Linear trend line

A regression equation is calculated and the associated linear trend line and R-squared value can be displayed on the scatterplot. The trend line models the linear relationship between the x and y fields, while the R-squared value indicates how well the trend line fits the data. A sloping upward trend line indicates a positive correlation, meaning that as the x values increase, the y values also tend to increase. A sloping downward trend line indicates a negative correlation, meaning that as the x values increase, the y values tend to decrease.

CodePen
Sandbox Download
This chart visualizes the relationship between average SAT scores and earnings, with a linear trend line indicating the upward correlation between the two variables. The R-squared value displayed in the legend indicates how well the trend line fits the data, with a value closer to 1 indicating a better fit.
  1. Set the showLinearTrend property to true to display the linear trend line and R-squared value on the scatterplot.
  2. Use the linearTrendSymbol property to customize the appearance of the linear trend line by providing a symbol object.
Linear trend line
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Scatterplot with linear trend</title>
<style>
html,
body,
arcgis-chart {
height: 100%;
margin: 0;
}
</style>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.2/"></script>
</head>
<body>
<arcgis-chart></arcgis-chart>
<script type="module">
const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js");
const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js");
const featureLayer = new FeatureLayer({
portalItem: {
id: "fcf794778a4d486eb0ce863ab71d40db",
},
});
const chartElement = document.querySelector("arcgis-chart");
const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" });
scatterplotModel.xAxisField = "SAT_Score_Average";
scatterplotModel.yAxisField = "Earnings";
scatterplotModel.showLinearTrend = true;
scatterplotModel.linearTrendSymbol = {
type: "esriSLS",
style: "esriSLSDashDotDot",
color: [255, 0, 0, 100],
width: 4,
};
5 collapsed lines
chartElement.model = scatterplotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>