[R] Obtain One Row From ggcorr() Matrix

Sam Rizzuto gerh|g4 @end|ng |rom gm@||@com
Fri May 8 05:23:14 CEST 2020


Hi all,

I am looking to obtain one column/row of a correlation matrix from my data using the function ggcorr() from library(GGally). 

As an example, using the mtcars dataset, I have the following code that can reproduce one row/column:

df <- cor(x = mtcars$mpg, y = mtcars[2:11], use = “everything”)
library(corrplot)
corrplot(df, tl.srt = 45, method = “color”, addCoef.col = “black”, cl.cex = 0.56)

This shows all the correlations between mpg. However using ggcorr() and plotting it:

ggcorr(mtcars, method = c(“everything”), label = TRUE, label_size = 2, label_round = 4)

It shows a much nice and prettier looking correlation plot but does it for all variables. 

I have tried putting mtcars$mpg and mtcars[,1] to only return the one row, but neither seem to work. 

Any ideas on how to do it using ggcorr()?

Thanks,
Sam



More information about the R-help mailing list