Are boxplots by default unable to produce the whiskers when there are just 2 values being input?

I am working with dataset rufi and the values input are 0.939425 and 0.734522222. The boxplot command yields only the box without the whiskers. The box has the upper edge as the max value and the lower edge as the minimum value.

Am I doing something wrong here?

EDIT: I am working with a dataset refined of 254 datapoints that are in 12 different groups and would like to compare the parameters with boxplots between the 12 groups. To do so I worked with boxplot(refined$highfeq ~ refined$taxa)

enter image description here

But this had a problem with small datasets (of 2) for some groups which resulted in the box plots plotting without whiskers and the lower and upper limits of the box plotting the min and max values respectively (see pink plot). This outcome is due to the fivesum function applied by the boxplot function which calculated the lower-hinge and upper-hinge to be equal to the min and max.

Is there a way to get R to plot the boxplots using exact percentiles instead of the fivesum function?

  • $\begingroup$ You want to make a five number summary out of ... two numbers? In fact if you follow Tukey's definitions of how the bounds at the ends of the whiskers are computed, the whisker ends will lie exactly on top of the hinges, and the hinges are the two observations you have. So the boxplot is exactly how it's supposed to look. Check fivenum(1:2). $\endgroup$
    – Glen_b
    Commented Oct 19, 2014 at 9:36
  • $\begingroup$ In fact I think that boxplots really don't make sense for fewer than five points and the best thing to do in small samples is simply plot the values. Otherwise the boxplot hides the lack of information (making five numbers when there are only two) that should be highlighted. $\endgroup$
    – Glen_b
    Commented Oct 19, 2014 at 9:53

1 Answer 1


R's boxplot function, by default, uses boxplot.stats to calculate the boxes, whiskers, etc... boxplot.stats calls the fivenum function:

 > fivenum(c(0.734522222, 0.939425))
 [1] 0.7345222 0.7345222 0.8369736 0.9394250 0.9394250

According to ?fivenum:

Tukey's five number summary (minimum, lower-hinge, median, upper-hinge, maximum)

The minimum and lower-hinge are identical. Similarly, the upper-hinge and maximum are identical.

  • $\begingroup$ Thanks for the indepth explanation about the resultant plot. If this is due to the default plotting function, is there any way to get R to plot min, lower quartile, median, upper quartile, max instead of minimum, lower-hinge, median, upper-hinge, maximum? $\endgroup$ Commented Oct 19, 2014 at 4:02
  • $\begingroup$ If you've only got two values, does a boxplot make sense? If you want to calculate quantiles, you could use the quantile function: quantile(c(0.734522222, 0.939425), probs = seq(0, 1, 0.25)), which would return this: 0% 25% 50% 75% 100% 0.7345222 0.7857479 0.8369736 0.8881993 0.9394250 $\endgroup$ Commented Oct 19, 2014 at 4:08
  • $\begingroup$ These 2 values are part of a larger dataset which I am comparing and this is the only group that has 2 values present, which resulted in a odd boxplot. $\endgroup$ Commented Oct 19, 2014 at 4:12
  • $\begingroup$ It sounds like you'd end up with something that looks like a boxplot, but it isn't really a boxplot. $\endgroup$ Commented Oct 19, 2014 at 4:19
  • 1
    $\begingroup$ So the usual rules imply that the two values are reported as both quartiles and extremes; hence whiskers exist in principle but are of zero length. It's undoubtedly a box plot, but you can't see structure implying more distinct values than you have. See also stats.stackexchange.com/questions/68069/…? and other questions of similar form. Consider a strip chart or plot for such data. $\endgroup$
    – Nick Cox
    Commented Oct 19, 2014 at 7:01

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.