jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.3k stars 230 forks source link

change order of kmean cluster #149

Closed HendrikCOS closed 6 years ago

HendrikCOS commented 6 years ago

Hi,

I did a semi-supervised kmean clustering on expression data and using complexHeatmap for visualisation. Using Heatmap(x, ..., split = km$cluster, ...) it nicely splits the corresponding cluster, however always in alphabetical order of the clusternames. Is there a way to customize the order? I want cluster which are more closely related to be next to each other. Therefore, I calculated the distance of these cluster and clustered them using hclust. Now I would like to use hclust$order to order the kmean cluster. Using row_order = ... does not make any difference.

Thank you for your help!

HendrikCOS commented 6 years ago

I found a workaround. I just renamed the km$cluster with letters in the way that the alphabetical order demonstrates the order of the cluster.

maybe not the most elegant way, but it works for me right now.

jokergoo commented 6 years ago

You did it right. If the split is a factor, the level of the factor determines the order of row clusters.

split = factor(km$cluster, levels = c(2, 1, 3))

the order will be cluster2, cluster1, and cluster3