Why 1st and 3rd quartiles don't match with boxplot in R?

a = c(3,12,15,16,16,17,19,34)
boxplot(a, horizontal = T)
abline(v=quantile(a), lty=2)

enter image description here


abline(v=fivenum(a), col="green")

enter image description here

  • 4
    $\begingroup$ You might want to add fivenum(a); abline(v=fivenum(a), col="green") to the end of your code and see the effect $\endgroup$
    – Henry
    Commented Jan 19, 2016 at 0:52
  • $\begingroup$ great! Outliers appears out of the range: quantile(a, c(1,3)/4) +/- 1.5*IQR(a) ?? $\endgroup$
    – Juanchi
    Commented Jan 19, 2016 at 0:58
  • 1
    $\begingroup$ @Juanchi the answer to the outliers question is also given by ?boxplot.stats (by default, coef is 1.5, and the discussion of coef under the heading Arguments tells you what it does). $\endgroup$
    – Glen_b
    Commented Jan 19, 2016 at 2:51

1 Answer 1


See ?boxplot.stats:

The two ‘hinges’ are versions of the first and third quartile, i.e., close to quantile(x, c(1,3)/4). The hinges equal the quartiles for odd n (where n <- length(x)) and differ for even n. Whereas the quartiles only equal observations for n %% 4 == 1 (n = 1 mod 4), the hinges do so additionally for n %% 4 == 2 (n = 2 mod 4), and are in the middle of two observations otherwise.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.