簡體   English   中英

相關矩陣圖中的變量標簽

[英]Variable labels in the correlation matrix plot

我想在相關矩陣圖中包括變量標簽以及變量名。

在R中有什么辦法嗎? 我的代碼:

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

提前致謝。

您可以嘗試我的package 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM