Reordering clusters when plotting pheatmap in R
1
0
Entering edit mode
ecg1g15 • 0
@ecg1g15-19970
Last seen 7 months ago

I am plotting a set of genes belonging to three groups A, B, C, and the heatmap orders them such as C, A, B. (I have read this is due to that it plots on the right the cluster with the strongest similarity). I would like to order the clusters to the groups are seen as A, B, C (therefore reorganising the order of the cluster branches.

> pheatmap(mat, annotation_col = anno, color = colorRampPalette(c("blue", "white", "red"))(50),show_rownames = F)


I have tried adding cluster_cols = FALSE. This orders the columns in sample number order (which is similar to dendrogram) but ignores the clustering which I am interested to see (ie. samples 1419 and 1421 are clustered together, but when using cluster_cols = FALSE sample 1420 shows in the middle.

pheatmap(mat, annotation_col = anno, cluster_cols = FALSE, color = colorRampPalette(c("blue", "white", "red"))(50),show_rownames = F)


is there any function I could use to specify (even manually) the order of the columns maintaining the clusters?

R pheatmap clusters • 1.8k views
0
Entering edit mode
ecg1g15 • 0
@ecg1g15-19970
Last seen 7 months ago

I have found you can use clustering_callback function, but I need to construct it, how do I do it?

clustering_callback callback function to modify the clustering. Is called with two parameters: original hclust object and the matrix used for clustering. Must return a hclust object.