我想在变量矩阵图中包含变量标签和变量名称。
R有什么办法吗? 我的代码:
library(corrplot)
corrplot(cor.mat, type="upper", order="hclust",
tl.col="black", tl.srt=45)
提前致谢。
答案 0 :(得分:0)
你可以尝试我的包expss
。解决方案不是那么完美,但在很多情况下帮助我:
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)