A couple months ago someone asked about putting regression equations
in each facet:
https://groups.google.com/d/topic/ggplot2/me5hL8XOxTo/discussion
Your question is a variant on this, so read the above link. Basically
you want to write a short function that will compute and return the
correlation (or whatever you want) for a subset of data, use ddply on
your data to generate a new data frame, and then annotate the facets
with geom_text.
Ben
On Mon, Jul 23, 2012 at 8:51 PM, hlm <
hideyos...@gmail.com> wrote:
> Hi guys,
>
> This is a copy of a question I put up on stack overflow, as I didn't realise
> there was a dedicated group for ggplot2 before I posted it, but thought I
> should let you guys know.
>
> Anyway here is the question and the link is below.
>
> When using a facet_grid in ggplot2 I would like to be able to have value of
> the correlation for the subsetted data for each grid cell in the top right
> corner of the specific plot.
>
> e.g. if running:
>
> p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
> p + facet_grid(vs ~ am, margins=TRUE)
>
> I would like to see the value for correlation for each of the 9 plots in the
> grid somewhere. In this specific case from the example, I would expect each
> to be close to -0.9 or so from visual inspection.
>
> Or perhaps an output table to go with the plot that gives the correlation
> values for each of the cells in the table matching up with the
> facet_grid...(this is less desirable but also an option).
>
> Ideally I would like to extend this to any other function I choose that so
> that it can use either or both of the two variables plotted to calculate
> statistics.
>
> Is this possible?
>
> Thanks in advance
>
>
>
http://stackoverflow.com/questions/11622526/correlation-values-in-a-facet-grid-from-ggplot2
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2