Horizontal binning in stat_summary

41 views
Skip to first unread message

thomas

unread,
Aug 3, 2010, 4:33:12 AM8/3/10
to ggplot2
Hi,

I looked for a while without success :(
Is it possible to bin values on the horizontal axis when using
stat_summary… This would allow much greater flexibility when
summarizing data will small jittering in x. I wondered if it would be
possible to use stat_bin but I doubt it is possible to call two stats
simultaneously. I'm probably missing something obvious…

Here is some small example to illustrate this point:

library(ggplot2)
d <- data.frame(a = rep(c(1,3,5), 10),
b = rnorm(30),
c = rep(1:10, each=3))

# works fine if points are aligned
qplot(a, b, data=d, color=factor(c), geom=c("point", "path")) +
stat_summary(fun.data="mean_cl_normal", geom = "errorbar", width=0.5,
colour="black")

# if the data are jittered (even tinily), no more summary can be
computed without binning
d$a2 <- jitter(d$a, 0.1)
qplot(a2, b, data=d, color=factor(c), geom=c("point", "path")) +
stat_summary(fun.data="mean_cl_normal", geom = "errorbar", width=0.5,
colour="black")


Thanks for your help,

Thomas

Hadley Wickham

unread,
Aug 6, 2010, 4:32:49 PM8/6/10
to thomas, ggplot2
Not currently, but it's usually pretty easy to do the summarising
yourself using ddply.
Hadley

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

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages