Zihu Guo
Zihu Guo

Reputation: 455

How can I get the new order of column and row in a heatmap after clusting using the pheatmap

I draw a heatmap using the 'pheatmap' package, and clusted with the rows and cloumns. However, for some reason, I need to get the row order and the column order in the heatmap. Is there a convient way to do that? This is a example of pheatmap.

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

pheatmap(test)

Upvotes: 1

Views: 4489

Answers (1)

Zihu Guo
Zihu Guo

Reputation: 455

I get the answer myself.

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

myheatmap <- pheatmap(test);
myheatmap$tree_row$order
#1  7  3  5  8  2 10  9  4  6 13 12 11 14 17 20 16 18 15 19

Upvotes: 4

Related Questions