[R] Boxplot Help

Gabor Grothendieck ggrothendieck at gmail.com
Fri Aug 18 20:17:17 CEST 2006


Try this:

result <- boxplot(Petal.Length ~ Species, iris)
if (length(result$out))
 text(result$group, result$out, match(result$out, iris$Petal.Length),
   pos = 4, col = "red")

If the outliers can be non-unique then match is not enough.
In that case assume that the nth occurrence of
any value in result$out is also the nth occurrence in the
vector boxplotted.  (Sort the data frame by group if that is
not the case.)   This assumption is sufficient to allow us to write
posof which gives the index into the data frame of any value in out.

# determine position of x in y
# assuming that if there are duplicates in x that
# they occur the same number of times and in
# the same order so that the 2nd occurrence of 37
# in x would correspond to the 2nd occurrence of 37 in y
posof <- function(x, y) {
   n <- sapply(seq(x), function(m) sum(x[m] == x[1:m]))
   mapply(function(x, n) which(y == x)[n], x, n)
}

result <- boxplot(Petal.Length ~ Species, iris)
if (length(result$out))
 text(result$group, result$out, posof(result$out, iris$Petal.Length),
   pos = 4, col = "red")



On 8/18/06, Ana Patricia Martins <ana.pmartins at ine.pt> wrote:
> Hello R-users and developers,
>
>
>
> Once again, I'm asking for your help.
>
> I can identify outliers in boxplot with this instruction
>
>
>
> result <- boxplot( Income ~ Sex,  col = "lightgray", data=dados)
>
> if (length(result$out))
>
>  text(result$group, result$out, result$out, pos = 4, col = "red")
>
>
>
> But I can not identify the outlier's id (variable names) in the boxplot.
>
> Can anyone help me?
>
> Thanks in advance,
>
>
>
> Atenciosamente,
>
> Ana Patricia Martins
>
> -------------------------------------------
>
> Serviço Métodos Estatísticos
>
> Departamento de Metodologia Estatística
>
> INE - Portugal
>
> Telef:  218 426 100 - Ext: 3210
>
> E-mail:  <mailto:ana.pmartins at ine.pt> ana.pmartins at ine.pt
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>



More information about the R-help mailing list