【问题标题】:Can you extract the data matrix from pheatmap in R?你能从 R 中的 pheatmap 中提取数据矩阵吗?
【发布时间】:2015-09-25 14:37:34
【问题描述】:

我根据基因微阵列数据创建了一个热图,然后使用该热图对数据进行聚类并输出一个热图。

有没有办法将热图的聚类数据以矩阵形式输出到excel文件中?

【问题讨论】:

  • 如果您将热图保存为对象,您可能能够访问数据。看看结构(str()),它很可能在那里

标签: r pheatmap


【解决方案1】:

一种方法是直接重现数据聚类。 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]

【讨论】:

    猜你喜欢
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    相关资源
    最近更新 更多