
我已经使用heatmap.3生成了这个热图。聚类是基于树状图执行的,但为了演示的目的,我想重新排序节点,以便在维护树状图的同时,使深蓝色位于左侧,深红色位于右侧。我读过关于重新排序的文章: newdendro<-reorder(as.dendrogram(myclust(mydist(heatdata.scaled))),10:1,agglo.FUN=colSums)
但colSums(heatdata.scaled)并未存储在树状图中。如何1)使用colSums(heatdata.scaled)对节点重新排序2)在热图中调用此更新的树状图。3)?
发布于 2016-05-31 02:18:12
你的问题缺少一个自包含的可重现的例子。因此,我将使用mtcars数据。由于我现在正在开发heatmaply包,因此我将使用它给出一个答案(但您只需将heatmaply更改为您想要的函数,代码将同样工作)。
# get data
x <- mtcars
# row dend:
hc_r <- as.dendrogram(hclust(dist(x)))
# col dend:
hc_c <- as.dendrogram(hclust(dist(t(x))))
# weights and reordering
wts_r <- rowSums(x)
wts_c <- colSums(x) # apply(x, 2, mean)
hc_r <- rev(reorder(hc_r,wts_r))
hc_c <- reorder(hc_c,wts_c)
x2 <- x[order.dendrogram(hc_r),
order.dendrogram(hc_c)]
# plot
library(heatmaply)
heatmaply(x2, dendrogram = "none")我们得到了下面这个漂亮的(交互式的)图:

https://stackoverflow.com/questions/37517678
复制相似问题