Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overall correlation in ggpairs with colour grouping?

This code produces a nice pairs plot that has a correlation read-out on the middle right:

library(GGally)
ggpairs(esoph[,c(1,4,5)], colour='agegp')

You can get just the correlation square with:

ggally_cor(data=esoph[,c(1,4,5)],
           mapping=aes(x=ncases, y=ncontrols, colour='agegp'))

The square contains a correlation per group. Is there any way to get the correlation for the over-all data set to appear as well? If you don't use colour=... then you get it, but then you don't get the per-group correlations.

like image 971
naught101 Avatar asked Aug 27 '12 07:08

naught101


People also ask

What does ggpairs tell you?

The ggpairs() function from the GGally package allows us to build a great scatterplot matrix. Scatterplots of each pair visualized in left side of the plot and Pearson correlation value and significance displayed on the right side.

What package is ggpairs in?

The ggpairs() function of the GGally package allows to build a great scatterplot matrix. Scatterplots of each pair of numeric variable are drawn on the left part of the figure. Pearson correlation is displayed on the right. Variable distribution is available on the diagonal.


1 Answers

I can now verify that this works with GGally_0.4.4 with R version 3.0.1 (2013-05-16) on Platform: x86_64-pc-linux-gnu (64-bit)

library(GGally)
ggally_cor(data=esoph[,c(1,4,5)],
       mapping=aes(x=ncases, y=ncontrols, colour='agegp'))

See that the overall correllation appears at the top and is consistent with the number I get from this command:

ggally_cor(data=esoph[,c(1,4,5)],
       mapping=aes(x=ncases, y=ncontrols))

like image 56
Statwonk Avatar answered Oct 17 '22 23:10

Statwonk