2015-09-25 42 views
0

我基于基因芯片数据创建了热图,然后使用pheatmap对数据进行聚类并输出热图。你能从R中的pheatmap中提取数据矩阵吗?

有什么方法可以将矩阵形式的热图集群数据输出到excel文件中吗?

+0

如果将热图保存为对象,则可以访问数据。看看结构('str()'),它可能就在那里 – erasmortg

回答

0

一种方法是直接重现数据聚类。 pheatmap的默认输入参数指定欧几里德距离和层次聚类。

下面的代码重现了pheatmap将在测试矩阵上执行的聚类。 reordered的内容是由pheatmap绘制的内容。

# load clustering library 
library(stats) 

# example matrix from pheatmap documentation 
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 = "") 

# cluster and re-order rows 
rowclust = hclust(dist(test)) 
reordered = test[rowclust$order,] 

# cluster and re-order columns 
colclust = hclust(dist(t(test))) 
reordered = reordered[, colclust$order]