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)
range(a)
quantile(a)
abline(v=quantile(a), lty=2)
@Henry:
abline(v=fivenum(a), col="green")
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.
Sign up to join this communitySee ?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.
fivenum(a); abline(v=fivenum(a), col="green")
to the end of your code and see the effect $\endgroup$?boxplot.stats
(by default,coef
is 1.5, and the discussion ofcoef
under the headingArguments
tells you what it does). $\endgroup$