CodePen
Sandbox Download

Distribution of life expectancy across different years and continents.

What is a box plot?

Box plots visualize the distribution of data and identify outliers. They provide a summary of a dataset by displaying its minimum, first quartile, median, third quartile, and maximum values. The box portion of the diagram illustrates the middle 50 percent of the data, while the whiskers extend to the minimum and maximum values within a specified range. Outliers are typically represented as individual points beyond the whiskers.

Data configurations

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

With one numeric field

Box plots with a single numeric field displays the distribution of that numeric field using the median, quartiles, whiskers and optional outliers. The following combinations are available:

FieldsResult
One numericFieldsDisplays the distribution of one numeric field using the median, quartiles, whiskers, and optional outliers.
One numericFields + categoryCreates a box plot for each category, allowing comparison across groups.
One numericFields + splitByFieldDivides the chart by a secondary grouping field, creating a box plot for each unique split-by value.
One numericFields + category + splitByFieldCreates grouped box plots for every category and split-by combination, allowing detailed comparison across multiple dimensions.
CodePen
Sandbox Download
This chart shows the distribution of life expectancy across different years and continents, with outliers displayed as individual points beyond the whiskers of the box plot.
  1. Set the numericFields property to ["life_expectancy"] to define the numeric values used to calculate the distribution.
  2. Set the category property to year_long to visualize how the distribution changes across different years.
  3. Set the splitByField property to continent to further break down the distribution by continent within each year.
  4. Set the showOutliers property to true to display outliers as individual points beyond the whiskers of the box plot.
Box plot with numeric, category, and split by fields
28 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Box plot with numeric field, category, and split-by</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: "c99e16e5573c47ab8c4536cb77673211",
},
});
const chartElement = document.querySelector("arcgis-chart");
const boxPlotModel = await createModel({ layer: featureLayer, chartType: "boxPlot" });
boxPlotModel.numericFields = ["life_expectancy"];
boxPlotModel.category = "year_long";
boxPlotModel.splitByField = "continent";
boxPlotModel.showOutliers = true;
8 collapsed lines
boxPlotModel.legendPosition = "top";
boxPlotModel.titleText = "Distribution of Life Expectancy by Year and Continent";
boxPlotModel.setAxisTitleText("Year", 0);
chartElement.model = boxPlotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

With multiple numeric fields

Box plots with multiple numeric fields display the distribution of each numeric field using the median, quartiles, whiskers, and optional outliers.

FieldsResult
Multiple numericFieldsDisplays one box plot for each numeric field. Values are standardized by default.
Multiple numericFields + categoryCreates a box plot for every category and numeric-field combination, allowing comparison across groups and variables.
Multiple numericFields + splitByFieldCreates a box plot for every split-by value and numeric-field combination, allowing comparison across groups and variables.
CodePen
Sandbox Download
This chart shows the distribution of life expectancy and income across different continents, the values are standardized to allow comparison between the two numeric variables with different units.
  1. Set the numericFields property to ["life_expectancy", "income_percap"] to define the numeric values used to calculate the distribution.
  2. Set the category property to continent to visualize how the distribution changes across different continents.
  3. Optionally, set the standardizeValues property to false if you want to disable the default z-score standardization and compare the numeric fields using their original units.
Box plot with multiple numeric fields and category field
28 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Box plot with numeric fields and category</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: "c99e16e5573c47ab8c4536cb77673211",
},
});
const chartElement = document.querySelector("arcgis-chart");
const boxPlotModel = await createModel({ layer: featureLayer, chartType: "boxPlot" });
boxPlotModel.numericFields = ["life_expectancy", "income_percap"];
boxPlotModel.category = "continent";
8 collapsed lines
boxPlotModel.legendPosition = "top";
boxPlotModel.titleText = "Distribution of Life Expectancy and Income by Continent";
boxPlotModel.setAxisTitleText("Continent", 0);
chartElement.model = boxPlotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>

Customization options

Mean lines

When a split by field is used with the box plot, the display mode of the chart can be changed to show the mean lines. This will create one box plot for each category or numeric field variable and use lines to show the mean for each unique value in the split by field.

CodePen
Sandbox Download
This chart shows the distribution of life expectancy across different years and continents, with mean lines displayed for each continent within each year.
  1. Set the showMeanLines property to true to display mean lines for each continent within each year.
  2. Use the meanLinesBoxColor property to set the color of the boxes. In this example, the color is set to a semi-transparent red with RGBA value of [255, 0, 0, 100].
Box plot with mean lines
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>ArcGIS Maps SDK for JavaScript Tutorials: Box 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: "c99e16e5573c47ab8c4536cb77673211",
},
});
const chartElement = document.querySelector("arcgis-chart");
const boxPlotModel = await createModel({ layer: featureLayer, chartType: "boxPlot" });
boxPlotModel.numericFields = ["life_expectancy"];
boxPlotModel.category = "year_long";
boxPlotModel.splitByField = "continent";
boxPlotModel.showMeanLines = true;
boxPlotModel.meanLinesBoxColor = [255, 0, 0, 100];
8 collapsed lines
boxPlotModel.legendPosition = "top";
boxPlotModel.titleText = "Distribution of Life Expectancy by Year and Continent";
boxPlotModel.setAxisTitleText("Year", 0);
chartElement.model = boxPlotModel;
chartElement.actionMode = "none";
</script>
</body>
</html>