【问题标题】:Getting row names from corrplot从 corrplot 获取行名
【发布时间】:2017-07-11 04:59:41
【问题描述】:

我在 corrplot 中使用 hclust 来生成绘图。由于聚类,列名的顺序与矩阵的顺序明显不同。有没有办法按照它们在图上出现的顺序来获取列名和行名?我有超过 625 行。

corrplot(trait.matrix, tl.cex = 0.3, col = col12(400), method = "color",
     cl.lim = c(0,1),  order="hclust", addgrid.col = NA, tl.col = "black")

【问题讨论】:

    标签: r plot r-corrplot


    【解决方案1】:

    corrplot 不可见地返回重新排列的矩阵。因此,您只需要将结果捕获到一个变量中,如下所示:

    cor <- cor(iris[,-5])
    result <- corrplot(cor, order="hclust")
    

    如您所见,corrplot 返回重新排列的矩阵:

    > cor
                 Sepal.Length Sepal.Width Petal.Length Petal.Width
    Sepal.Length    1.0000000  -0.1175698    0.8717538   0.8179411
    Sepal.Width    -0.1175698   1.0000000   -0.4284401  -0.3661259
    Petal.Length    0.8717538  -0.4284401    1.0000000   0.9628654
    Petal.Width     0.8179411  -0.3661259    0.9628654   1.0000000
    
    
    > result
                 Sepal.Width Sepal.Length Petal.Length Petal.Width
    Sepal.Width    1.0000000   -0.1175698   -0.4284401  -0.3661259
    Sepal.Length  -0.1175698    1.0000000    0.8717538   0.8179411
    Petal.Length  -0.4284401    0.8717538    1.0000000   0.9628654
    Petal.Width   -0.3661259    0.8179411    0.9628654   1.0000000
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 2021-12-02
      相关资源
      最近更新 更多