Winston Chang offered an answer to ggplot2 ... that's what he said ... this is not a bad answer ...
You can do something like this:
p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() # Calculate correlation for each group cors <- ddply(mtcars, c("vs", "am"), summarise, cor = round(cor(mpg, wt), 2)) p + facet_grid(vs ~ am) + geom_text(data=cors, aes(label=paste("r=", cor, sep="")), x=30, y=4)
I do not think that this can be done correctly with fields = TRUE. If you need fields, you may need to pre-process your data to add an ALL value for each cut variable.
Winston
source share