Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

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

share|improve this question
1  
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. –  Stephan Kolassa Nov 16 '12 at 8:52
1  
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. –  Glen_b Nov 16 '12 at 9:35
1  
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. –  Peter Flom Nov 16 '12 at 11:51
    
@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. –  naught101 Nov 22 '12 at 5:56
add comment

1 Answer 1

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)

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

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

share|improve this answer
1  
(+1) I would say points(jitter(rep(1, length(bar$out))), bar$out) is shorter :-) –  chl Nov 22 '12 at 10:25
    
@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? –  Stephan Kolassa Nov 22 '12 at 10:29
1  
Yes sorry, I wrote quickly: check the outline= argument to boxplot(). (You'll need to manage the y-axis limits, though.) –  chl Nov 22 '12 at 10:33
    
@chl: thank you, that definitely helps! I edited the original proposal. –  Stephan Kolassa Nov 22 '12 at 10:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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