Hi
Problem with cluster_col in pheatmap.
I am attempting to pass an hclust object (hc) to pheatmap and have found that it will correctly construct the dendrogram on the clusters, but the order of the tiles/columns in the actual heatmap is incorrect.
pheatmap code:
heat <- pheatmap(
mat = t(data),
color = viridis(10),
breaks = group_breaks,
annotation_col = group_col,
annotation_colors = group_col_colours,
cluster_cols = hc,
cluster_rows = FALSE,
border_color = NA,
show_colnames = TRUE,
drop_levels = TRUE,
main = "Heatmap"
)
Dendrogram:
Column order:
When I investigate hc$tree and heat$tree_col$order this matches the order of the columns:
hc$order
[1] 31 3 9 28 1 23 12 16 4 29 11 2 5 27 6 30 19 20 14 17 10 21 18 22 13 25 8 26 24
[30] 7 15 54 35 50 38 47 34 37 40 43 51 53 49 52 39 44 42 48 41 45 33 36 32 46
heat$tree_col$order
[1] 31 3 9 28 1 23 12 16 4 29 11 2 5 27 6 30 19 20 14 17 10 21 18 22 13 25 8 26 24
[30] 7 15 54 35 50 38 47 34 37 40 43 51 53 49 52 39 44 42 48 41 45 33 36 32 46
Which makes sense given that in the function tree_col is set to hc$order.
In short, how can I ensure that the column order of pheatmap matches the displayed order of the dendrogram (as shown in above images?) in pheatmap? I have tried ordering the dendrogram (dendsort), but to no avail.
this might of some help extract dendrogram cluster from pheatmap