tamfad4
tamfad4

Reputation: 1

Getting row names from corrplot

I used hclust in corrplot to produce a plot. The order of the colnames is different from that of the matrix obviously because of the clustering. Is there a way to get the column and row names in the order they appear on the plot? I have more than 625 rows.

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")

Upvotes: 0

Views: 283

Answers (1)

Karolis Koncevičius
Karolis Koncevičius

Reputation: 9656

corrplot returns the rearranged matrix invisibly. So you just need to catch that result in a variable like so:

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

as you can see corrplot returns the rearranged matrix:

> 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

Upvotes: 0

Related Questions