使用aheatatmap / heatmap2时显示R中树形图的比例

时间:2014-03-17 22:41:49

标签: r cluster-analysis hierarchical-clustering

如何在调用NMF包aheatmapheatmap.2时将R绘制成树形图(以便可以解释每个树形图的高度)以及热图?这些树形图显示了比例:http://gastonsanchez.com/blog/how-to/2012/10/03/Dendrograms.html 这是执行plot(hclust(...))的默认行为,我希望模仿但不确定如何通过heatmap函数执行此操作。

1 个答案:

答案 0 :(得分:1)

此处的问题是heatmap.2如何绘制dendrogram对象。 heatmap.2使用代码plot(ddr, horiz = TRUE, axes = TRUE, yaxs = "i", leaflab = "none"),其中ddr是树形图。您希望axes参数为FALSE。作为一种解决方法,我创建了heatmap.2函数的修改版本。有关详细信息,请参阅?plot.dendrogram

x = matrix( rnorm(25), ncol=5 )
f = gplots:::heatmap.2

# Edit the appropriate lines of the heatmap.2 function
print(body(f)[[75]]) # The line to edit
# if (dendrogram %in% c("both", "row")) {
#   plot(ddr, horiz = TRUE, axes = FALSE, yaxs = "i", leaflab = "none")
# } else plot.new()
body(f)[[75]][[3]][[2]][[4]] = TRUE

print(body(f)[[77]])
# if (dendrogram %in% c("both", "column")) {
#   plot(ddc, axes = FALSE, xaxs = "i", leaflab = "none")
# } else plot.new()
body(f)[[77]][[3]][[2]][[3]] = TRUE

f(x)

enter image description here