简体   繁体   中英

Variable labels in the correlation matrix plot

I would like to include the variables labels along with variable names in the correlation matrix plot.

Is there any way to do in R? my code:

library(corrplot)
corrplot(cor.mat, type="upper", order="hclust", 
         tl.col="black", tl.srt=45)

Thanks in advance.

You could try my package expss . Solution is not so perfect but helps me in many cases:

library(corrplot)
library(expss)

data(iris)
iris2 = iris[,-5] # drop 'Species' - factor variable

# apply labels
var_lab(iris2$Sepal.Length) = "Sepal Length"
var_lab(iris2$Sepal.Width) = "Sepal Width"
var_lab(iris2$Petal.Length) = "Petal Length"
var_lab(iris2$Petal.Width) = "Petal Width"

# for each variables add variable name to label 
for (each in colnames(iris2)){
    var_lab(iris2[[each]]) = paste(each, var_lab(iris2[[each]]))
}

# replace names with labels and build correlation matrix
cor.mat = cor(names2labels(iris2))

corrplot(cor.mat, type="upper", order="hclust", 
         tl.col="black", tl.srt=45)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM