Question: Pheatmap: Cluster columns on hclust object
0
gravatar for michaeljon.rosslee
15 months ago by
michaeljon.rosslee0 wrote:

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.

pheatmap R cluster • 1.1k views
ADD COMMENTlink modified 15 months ago by Kevin Blighe69k • written 15 months ago by michaeljon.rosslee0
1

this might of some help extract dendrogram cluster from pheatmap

ADD REPLYlink written 15 months ago by krushnach80860
2
gravatar for Kevin Blighe
15 months ago by
Kevin Blighe69k
Republic of Ireland
Kevin Blighe69k wrote:

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 COMMENTlink written 15 months ago by Kevin Blighe69k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2047 users visited in the last hour
_