If I have a set of data and I want to display it as a boxplot, when there are some outliers in the boxplot, we indicate outliers with a
*. If there are two outliers having the same value, how to put that in the boxplot? Is it still *?
I'll use R in proposing a solution. Let's simulate some data:
set.seed(1) foo <- c(rnorm(100,0,1),5,5,5,7,7)
I see two possibilities. The first one would be to plot the boxplot and add sunflowerplots of the outliers:
bar <- boxplot(foo) sunflowerplot(x=rep(1,length(bar$out)),bar$out,seg.col=1,add=TRUE)
The second possibility is to plot the boxplot (which creates a single point for each outlier) and add additional points for additional outliers - which are jittered horizontally (edited as per @chl's excellent suggestion):
bar <- boxplot(foo,plot=FALSE) boxplot(foo,outline=FALSE,ylim=c(min(c(bar$stats,bar$out)),max(c(bar$stats,bar$out)))) points(jitter(rep(1, length(bar$out))), bar$out)
Note that the first solution requires that your data are integers (otherwise you will run afoul of floating-point arithmetic, see question 7.31 in the R FAQ - in this case you will need to do some additional work to ensure R knows which floating point numbers should be treated as "equal").
Late to the party, but "Don't do that then!" is sometimes a fair answer.
The box plot was a reinvention by John W. Tukey in the late 1960s of dispersion diagrams -- in geography literature from the 1930s -- and of range-bar plots -- in statistical literature from the 1940s. He supplied (in no particular order)
- a catchier name
- a sharp focus on being aware both of broad features such as level, spread, and shape and of specific details, especially wilder data points
- a rule of thumb for identifying individual points worth thinking about.
On #3 careful reading shows that Tukey tried various rules of thumb over several years of experiment. The rule now most often used -- plot as individual data points values that fall more than 1.5 IQR away from the nearer quartile -- was never more than one possible compromise. It's documented that he replied laconically to "Why 1.5?" with "1 is too small and 2 is too large". (I tend to prefer a rule such as: extend the whiskers to the $p$% and $(100 - p)$% quantiles.)
On #3 it is especially unfortunate that Tukey's exploratory purpose of identifying points to think about has in some quarters been perverted into an exclusion criterion for identifying bad data points that should be dropped from the dataset, or at least omitted from analyses.
It's worth underlining that Tukey's main context was quick and easy data plotting by hand with a minimum of work. Now it's naturally easy to plot if not all the data, then very many more than a box plot often shows -- and it's possible to do so without overwhelming the reader with detail. There is more than one way to do that, but here is a quantile plot of an example resembling that of @Stephan Kolassa, 100 points from a standard normal, 2 instances of 5 and 3 of 7. The box shown alongside is reduced to doing what it does best, showing by way of summary where the central half lies. The whiskers don't have much of a role, but I show them any way. Seeing repeated data points is not too hard. (I don't much favour sunflower plots, if only for the chicken-and-egg reason that as they aren't widely used, you have to explain them every time you use them.)
It's also entirely possible to superimpose the box and the quantile plot, as Emanuel Parzen suggested.
I used Stata, but something similar should be easy in your own favourite software. If not, you need new favourite software. (Having 2 5s and 3 7s, not vice versa, was a trivial error compared with emulating Stephan's code.)
clear set seed 2803 set obs 105 gen whatever = cond(_n <= 100, rnormal(0, 1), cond(_n < 103, 5, 7)) ssc install stripplot stripplot whatever, yla(, ang(h)) cumul cumprob vertical iqr box(barw(0.1)) boffset(-0.1) refline reflevel(median) aspect(1)