Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R draw heatmap with clusters, but hide dendrogram

By default, R's heatmap will cluster rows and columns:

mtscaled = as.matrix(scale(mtcars))
heatmap(mtscaled, scale='none')

enter image description here

I can disable the clustering:

heatmap(mtscaled, Colv=NA, Rowv=NA, scale='none')

And then the dendrogram goes away:enter image description here

But now the data is not clustered anymore.

I don't want the dendrograms to be shown, but I still want the rows and/or columns to be clustered. How can I do this?

Example of what I want:enter image description here

like image 844
Superbest Avatar asked Apr 27 '15 10:04

Superbest


1 Answers

You can rely on base R structures and consider following approach based on building the hclust trees by yourself.

mtscaled = as.matrix(scale(mtcars))
row_order = hclust(dist(mtscaled))$order
column_order = hclust(dist(t(mtscaled)))$order
heatmap(mtscaled[row_order,column_order], Colv=NA, Rowv=NA, scale="none")

No need to install additional junk.

like image 123
Martin Fridrich Avatar answered Sep 26 '22 03:09

Martin Fridrich