[英]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? 在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
. 您可以尝试我的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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.