D3-graph-gallery icon indicating copy to clipboard operation
D3-graph-gallery copied to clipboard

Boxplot calculations are incorrect

Open jtr13 opened this issue 5 years ago • 1 comments

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.

jtr13 avatar Nov 21 '19 17:11 jtr13

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.

lrusso96 avatar Mar 01 '20 11:03 lrusso96