Boxplot and IQR

Learn how to read boxplots, calculate IQR, and detect outliers in data.

BeginnerData VisualizationOutliersBoxplotIQR

Are mean and variance enough to summarize data?

In statistics, mean and variance are commonly used to summarize datasets.
However, these values alone do not always provide the full picture, especially regarding skewness or the presence of outliers.

For example:

  • The mean is highly sensitive to extreme values (outliers).
  • The variance shows overall spread but does not reveal where most data points are concentrated.

To address this, we often use a boxplot.


What is a boxplot?

A boxplot is a visual summary of data distribution. It highlights:
the median, quartiles, spread of the data, and potential outliers all in one diagram.

A boxplot consists of:

  • Box
    Represents the middle 50% of the data (from Q1 to Q3).
  • Line inside the box
    The median (Q2).
  • Whiskers
    Typically extend to the minimum and maximum values, excluding outliers.
  • Dots (●)
    Outliers that fall outside the whiskers.

Quartiles and IQR

To define quartiles, first sort the data in ascending order:

  • Q1 (first quartile): the 25th percentile
  • Q2 (median): the 50th percentile
  • Q3 (third quartile): the 75th percentile

The interquartile range (IQR) is:

IQR=Q3Q1IQR = Q3 - Q1

This measures the spread of the middle 50% of the data.


Defining outliers

A common rule defines outliers using IQR:

  • Lower bound:
    Q11.5×IQRQ1 - 1.5 \times IQR
  • Upper bound:
    Q3+1.5×IQRQ3 + 1.5 \times IQR

Any point outside this range is considered an outlier and shown as a dot beyond the whiskers.


Example

Dataset:
[2, 4, 5, 7, 8, 10, 15, 18, 20]

  1. Data is already sorted.
  2. Median (Q2) = 8
  3. Q1 = 4.5 (median of 2 and 7)
  4. Q3 = 16.5 (median of 15 and 18)
  5. IQR = 16.5 - 4.5 = 12

Outlier detection:

  • Lower bound = 4.51.5×12=13.54.5 - 1.5 \times 12 = -13.5
  • Upper bound = 16.5+1.5×12=34.516.5 + 1.5 \times 12 = 34.5

All points fall within this range, so no outliers exist.


Interactive Demo

In the demo below, you can choose from preset datasets to explore boxplots.
The tool will automatically calculate quartiles, IQR, and highlight outliers.

Interactive Boxplot Explorer

Choose different datasets to explore how boxplots reveal data distribution, quartiles, and outliers.

Well-balanced data with no outliers

📱 On mobile: Scroll horizontally to see the full plot

Dataset Values

Data: [12, 15, 16, 18, 20, 21, 22, 24, 25, 26, 28, 30, 32, 35, 38]

How to read this vertical boxplot:

  • • The box contains the middle 50% of data (from Q1 to Q3)
  • • The thick line inside the box shows the median (Q2)
  • • The whiskers extend to the furthest non-outlier points
  • Red dots represent outliers beyond 1.5 × IQR from the quartiles
  • Blue dots on the right show all individual data points
  • Quartile labels are positioned on the left with connecting dotted lines
← Back to Encyclopedia