[R] label outliers in geom_boxplot (ggplot2)

hadley wickham h.wickham at gmail.com
Fri Jun 6 17:36:30 CEST 2008


> It's too obvious, so I am positive that there is a good reason for not doing
> this, but still:
> why is it not possible, to have an "outlier" output in stat_boxplot that can
> be used at geom_text()?
>
> Something like this, with "upper":
>   > dat=data.frame(num=rep(1,20), val=c(runif(18),3,3.5),
> name=letters[1:20])
>   > ggplot(dat, aes(y=val, x=num))+stat_boxplot(outlier.size=4,
>   + outlier.colour="green")+geom_text(aes(y=..upper..), label="This is upper
> hinge")
>
> Unfortunately, this does not work and gives the error message:
>   Error in eval(expr, envir, enclos) : object "upper" not found
>
> Is it because you can only use stat outputs within the stat statements?
> Could it be possible to make them available outside the statements too?

You can generally, but it won't work here.  The problem is that you
want a different y aesthetic for the statistic (val) than you do for
the geom (upper)  and there's no way to get around that with the
current design of ggplot2.

Hadley


-- 
http://had.co.nz/



More information about the R-help mailing list