Ron*_*man 5 r cluster-analysis heatmap
请使用以下代码:
heatmap(data.matrix(signals),col=colors,breaks=breaks,scale="none",Colv=NA,labRow=NA)
Run Code Online (Sandbox Code Playgroud)
如何提取,预先计算或重新计算生成的热图中行的顺序?有没有办法将输出hclust(dist(signals))注入热图功能?
Ron*_*man 12
感谢Jesse和Paolo的反馈.我编写了以下排序函数,希望对其他人有用:
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)
Run Code Online (Sandbox Code Playgroud)
有多种选择。如果您运行,?heatmap您将看到可以调整的各种参数。也许最简单的方法是设置Rowv=NA哪个应该抑制行重新排序,然后将矩阵与已经按您想要的顺序的行一起传递。但你也可以手动提供群集功能,或树状图,通过Rowv和hclustfun等...
| 归档时间: |
|
| 查看次数: |
27256 次 |
| 最近记录: |