Summary statistic for each facet

11 views
Skip to first unread message

Felix Schönbrodt

unread,
Sep 10, 2009, 11:20:20 AM9/10/09
to ggplot2
Hi there,

in Lattice I used to dig into a facetted panel function, calculate the
correlation of each x-y scatterplot and print the correlation as an
annotation into each facet.

Is something similar possible in ggplot2? I know that I can compute
each facet's correlation outside of ggplot2 and do an annotation with
geom_text; however it would be more convenient if the calculations
were done automatically accordingly to the facets specified.

Thanks,
Felix

hadley wickham

unread,
Sep 12, 2009, 9:51:26 AM9/12/09
to Felix Schönbrodt, ggplot2
> Is something similar possible in ggplot2? I know that I can compute
> each facet's correlation outside of ggplot2 and do an annotation with
> geom_text; however it would be more convenient if the calculations
> were done automatically accordingly to the facets specified.

It would be convenient, but to work generally it would require an
infrastructure within ggplot2 for performing any kind of data
manipulation that you can imagine. I don't think that this is a good
idea in general, so I recommend performing your manipulations outside
of ggplot2. The plyr package is a natural fit for this sort of
activity:

cors <- ddply(mydf, c("group", "trt"), summarise, cor = cor(x, y))

Hadley

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

Felix Schönbrodt

unread,
Sep 12, 2009, 9:56:03 AM9/12/09
to hadley wickham, ggplot2
Hi Hadley,

thanks for your reply - that seems convenient enough! ;-)
I haven't delved into the plyr-package so far, maybe I should do now ...

Best,
Felix

Reply all
Reply to author
Forward
0 new messages