D3-graph-gallery
D3-graph-gallery copied to clipboard
Boxplot calculations are incorrect
The calculations below from https://www.d3-graph-gallery.com/graph/boxplot_basic.html are not correct.
var min = q1 - 1.5 * interQuantileRange
var max = q1 + 1.5 * interQuantileRange
Outliers are more than 1.5 * IQR above Q3 and below Q1. Those cutoffs are called fences. The whiskers are not fences: they indicate the highest and lowest nonoutlier data values.
See: https://ggplot2.tidyverse.org/reference/geom_boxplot.html
If you don't want to indicate outliers than just set min and max to the min and max values of the dataset.
The correct way should be:
var min = d3.max([d3.min(data), q1 - 1.5 * interQuantileRange])
var max = d3.min([d3.max(data), q1 + 1.5 * interQuantileRange])
Hope it helps.