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 demonstrates how different data configurations can be used to create various types of box plots, including configurations with a single numeric field or multiple numeric fields, and the use of category and split by fields to further break down the data.
With one numeric field
Box plots with a single numeric field specified via the numericFields property displays the distribution of that numeric field using the median, quartiles, whiskers and optional outliers.
- Along with a category field specified via the
categoryproperty, boxs are created for each category, allowing comparison across groups. - Along with a split by field specified via the
splitByFieldproperty, the chart is divided by a secondary grouping field, creating separate box plots for each unique split by value. - Along with both category and split by fields specified via the
categoryandsplitByFieldproperties, grouped box plots are created for every category and split by combination, allowing detailed comparisons across multiple dimensions.
The above 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.
- Set the
numericFieldsproperty to["life_expectancy"]to define the numeric values used to calculate the distribution. - Set the
categoryproperty toyear_longto visualize how the distribution changes across different years. - Set the
splitByFieldproperty tocontinentto further break down the distribution by continent within each year. - Set the
showOutliersproperty totrueto display outliers as individual points beyond the whiskers of the box plot.
29 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: 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.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: "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;9 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 specified via the numericFields property displays the distribution of each numeric field using the median, quartiles, whiskers and optional outliers.
A z-score standardization is applied by default, allowing numeric variables of different units to be comparable. To disable standardization, set the standardizeValues property to false.
- Along with a category field specified via the
categoryproperty, box plots are created for each category and numeric field combination, allowing for comparison of distributions across different groups and numeric variables. - Along with a split by field specified via the
splitByFieldproperty, box plots are created for each split by value and numeric field combination, allowing for comparison of distributions across different groups and numeric variables.
The above 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.
- Set the
numericFieldsproperty to["life_expectancy", "income_percap"]to define the numeric values used to calculate the distribution. - Set the
categoryproperty tocontinentto visualize how the distribution changes across different continents.
29 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: 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.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: "c99e16e5573c47ab8c4536cb77673211", }, }); const chartElement = document.querySelector("arcgis-chart"); const boxPlotModel = await createModel({ layer: featureLayer, chartType: "boxPlot" });
boxPlotModel.numericFields = ["life_expectancy", "income_percap"]; boxPlotModel.category = "continent";9 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 by setting the showMeanLines property to true.
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.
The above chart shows the distribution of life expectancy across different years and continents, with mean lines displayed for each continent within each year.
- Set the
showMeanLinesproperty totrueto display mean lines for each continent within each year. - Use the
meanLinesBoxColorproperty to set the color of the boxes that highlight the mean lines. In this example, the color is set to a semi-transparent red with RGBA value of[255, 0, 0, 100].
32 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.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: "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];9 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>