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 demonstrates how different data configurations can be used to create various types of scatterplots.
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.
The above 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.
- Set the
xAxisFieldproperty to"SAT_Score_Average"and theyAxisFieldproperty to"Earnings", which are both integer fields.
30 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Esri Developer Guide: 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.1/"></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";6 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>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.
The above 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.
- Set the
sizePolicyproperty to an object withtypeset to"sizeScale",scaleTypeset to"linear",fieldset to"TUITIONFEE", and specify theminSizeandmaxSizefor the points.
32 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Esri Developer Guide: 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.1/"></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, };6 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>Customization options
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.
The above 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.
- Set the
showLinearTrendproperty totrueto display the linear trend line and R-squared value on the scatterplot. - Use the
linearTrendSymbolproperty to customize the appearance of the linear trend line by providing a symbol object.
32 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Esri Developer Guide: 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.1/"></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, };6 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>