What's your boxplot and data look like?
B
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
mtcars.size <- ddply(mtcars, .(cyl), summarize, mpg=mean(mpg), n=length(mpg))
p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot() + geom_text(aes(label=paste("n =", n)), data=mtcars.size)
-Ista
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
On Thu, Sep 30, 2010 at 11:38 PM, jacktanner <ih...@hotmail.com> wrote:
> Ista, that's a great suggestion. That method works for the mtcars
> data, but it doesn't work in a more complicated case:
>
> mydf=data.frame(list(
> f1=factor(rep(c("a","b"), each=15)),
> f2=factor(rep(c("x","y","z"), each=5)),
> y=as.vector(sapply(1:6, function(x) { rnorm(5, x, 1) }))
> ))
>
>> mydf.size <- ddply(mydf, .(f1, f2), summarise, y=mean(y), n=length(y))
>> p = ggplot(mydf) + geom_boxplot(aes(x=f1, y=y, fill=f2))
>> p + geom_text(aes(label=paste("n =", n)), data=mydf.size)
>
> Error in which(cat) : argument to 'which' is not logical
>
One thing I notice about this is that geom_text might not know what
any of it's aesthetics are, because none are specified in the ggplot
call or in the geom_text call. So move the x, y, and fill
specification out of the geom_boxplot call and into the ggplot call:
p <- ggplot(mydf, aes(x=f1, y=y, fill=f2)) + geom_boxplot()
p + geom_text(aes(label=paste("n =", n), group = f2), data=mydf.size)
that almost worked except that the text labels were stacked instead of
dodged. So I tried
p + geom_text(aes(label=paste("n =", n), group = f2), data=mydf.size,
position=position_dodge(width=.75))
and that seems to work (the width=.75 was arrived at by trial and error).
Best,
Ista