for the below example of showing correlation values in a facet plot, how can you alter the colour of the text according to the correlation value and specifically i would like it to be a scale which goes brighter red for more negative correlations and a brighter blue for more positive correlations...is this possible?
this seems simple but not quite sure how to do it....any help would be much appreciated
That looks great, thanks, and as a bit of a follow up question, is there anyway to determine where the "space" is for each facet grid cell, so that the correlation figure could be put there, rather than having it hard coded.
Thanks for the speedy reply.
On Tuesday, 24 July 2012 11:41:04 UTC+10, winston wrote:
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.