【问题标题】:Variable labels in the correlation matrix plot相关矩阵图中的变量标签
【发布时间】:2017-01-12 13:11:01
【问题描述】:

我想在相关矩阵图中包含变量标签和变量名称。

在 R 中有什么办法吗? 我的代码:

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

提前致谢。

【问题讨论】:

    标签: r correlation r-corrplot


    【解决方案1】:

    你可以试试我的包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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2013-09-15
      • 2021-11-24
      相关资源
      最近更新 更多