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 *?

  • 1
    $\begingroup$ Could you be a little more specific? Are you asking about the input data to a boxplot (where you could of course have duplicate values) or about the output values a boxplot function may report? The last will probably depend on your software. For instance, the boxplot() function in R will report multiple identical outliers separately: boxplot(c(rnorm(100,0,1),5,5))$out yields two separate outliers of value 5. $\endgroup$ – Stephan Kolassa Nov 16 '12 at 8:52
  • 1
    $\begingroup$ There are several possibilities. Some programs - especially older ones using test-based display - will use a '2', '3' etc to indicate how many values are there. Other programs will show two stars (or circles or whatever) together. $\endgroup$ – Glen_b -Reinstate Monica Nov 16 '12 at 9:35
  • 1
    $\begingroup$ Are you asking about doing boxplots by hand or about how some software does this? As @Glen_b said, different software will do different things. $\endgroup$ – Peter Flom - Reinstate Monica Nov 16 '12 at 11:51
  • $\begingroup$ @StephanKolassa: I think the point is that they are plotted over the top of each other, so you can't see that there's two. $\endgroup$ – naught101 Nov 22 '12 at 5:56

I'll use R in proposing a solution. Let's simulate some data:

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)

sunflowerplotted outliers

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)
points(jitter(rep(1, length(bar$out))), bar$out)

jittered outliers

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").

  • 1
    $\begingroup$ (+1) I would say points(jitter(rep(1, length(bar$out))), bar$out) is shorter :-) $\endgroup$ – chl Nov 22 '12 at 10:25
  • $\begingroup$ @chl: yes, that would be shorter... but then we would have n+1 points where only n should be for n outliers with the same value: one from the original boxplot and n from overplotting the jittered points. This is why I used the cumbersome table() stuff. (It would be easier if there were a way to tell boxplot() not to plot the outliers.) Or am I mistaken? $\endgroup$ – Stephan Kolassa Nov 22 '12 at 10:29
  • 1
    $\begingroup$ Yes sorry, I wrote quickly: check the outline= argument to boxplot(). (You'll need to manage the y-axis limits, though.) $\endgroup$ – chl Nov 22 '12 at 10:33
  • $\begingroup$ @chl: thank you, that definitely helps! I edited the original proposal. $\endgroup$ – Stephan Kolassa Nov 22 '12 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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