9

次のコードを取ります。

 heatmap(data.matrix(signals),col=colors,breaks=breaks,scale="none",Colv=NA,labRow=NA)

作成されたヒートマップの行の順序を抽出、事前計算、または再計算するにはどうすればよいですか?hclust(dist(signals))の出力をヒートマップ関数に注入する方法はありますか?

4

5 に答える 5

15

フィードバックをありがとう、ジェシーとパオロ。うまくいけば他の人に役立つ次の順序付け関数を書きました。

data        = data.matrix(data)
distance    = dist(data)
cluster     = hclust(distance, method="ward")
dendrogram  = as.dendrogram(cluster)
Rowv        = rowMeans(data, na.rm = T)
dendrogram  = reorder(dendrogram, Rowv)

## Produce the heatmap from the calculated dendrogram.
## Don't allow it to re-order rows because we have already re-ordered them above.

reorderfun = function(d,w) { d }
png("heatmap.png", res=150, height=22,width=17,units="in")

heatmap(data,col=colors,breaks=breaks,scale="none",Colv=NA,Rowv=dendrogram,labRow=NA, reorderfun=reorderfun)

dev.off()


## Re-order the original data using the computed dendrogram
rowInd = rev(order.dendrogram(dendrogram))
di = dim(data)
nc = di[2L]
nr = di[1L]
colInd = 1L:nc
data_ordered <- data[rowInd, colInd]
write.table(data_ordered, "rows.txt",quote=F, sep="\t",row.names=T, col.names=T)
于 2011-03-16T17:56:02.643 に答える
6

さまざまなオプションがあります。実行する?heatmapと、微調整できるさまざまなパラメータが表示されます。おそらく最も簡単なのは、Rowv=NA行の並べ替えを抑制するように設定してから、行が既に必要な順序になっている行列を渡すことです。Rowvただし、クラスタリング機能や樹状図を手動で提供することもできますhclustfun

于 2011-03-16T03:54:42.143 に答える