Pheatmap: Cluster columns on hclust object
1
0
Entering edit mode
5.1 years ago

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: Dendrogram

Column order: 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.

R pheatmap cluster • 5.0k views
ADD COMMENT
1
Entering edit mode
ADD REPLY
2
Entering edit mode
5.1 years ago

I am not sure what you mean. When I do it, they align:

#Create random data
data <- replicate(20, rnorm(50))
rownames(data) <- paste("Gene", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

hc <- hclust(dist(t(data)))
plot(hc)

ddd

out <- pheatmap(data, cluster_cols = hc)

ff

out$tree_col$order
 [1] 18  2  9 16 17 19 15  1 14 20  3  7 11 13  5 12  4  6  8 10
ADD COMMENT

Login before adding your answer.

Traffic: 2516 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6