Question: How to cluster the annotation in the heat map?
0
gravatar for ravi
8 months ago by
ravi20
ravi20 wrote:
library(ComplexHeatmap)

set.seed(123)
mat = matrix(rnorm(100), 10)
foo = sample(letters[1:2], 10, replace = TRUE)
colnames(mat) = sapply(letters[1:10], function(x) paste(rep(x, 10), collapse = ""))
cn = colnames(mat)
ha2 = HeatmapAnnotation(foo = foo,
                cn = anno_text(cn, rot = 90, offset = unit(1, "npc") - unit(2, "mm"), just = "right"),
                annotation_height = unit.c(unit(5, "mm"), max_text_width(cn)))
Heatmap(mat, show_column_names = FALSE, bottom_annotation = ha2)

This gave me a heat map like following:

https://imgur.com/CHQdXyb

Here you see in the bottom annotation both a and b are not clustered. I would like to know how can I do each group (color) get clustered. I mean all samples which come under "b" at one side and samples under "a" on one side.

Can anyone please tell me how to do this? Thanks !!

heatmap rna-seq clustering R • 327 views
ADD COMMENTlink modified 8 months ago by Kevin Blighe21k • written 8 months ago by ravi20
1
gravatar for Kevin Blighe
8 months ago by
Kevin Blighe21k
University College London Cancer Institute
Kevin Blighe21k wrote:

ComplexHeatmap doesn't support splitting that way - it only supports splitting by rows. If you want to split by columns, you could just generate two separate heatmaps and plot them side by side with the draw function draw(hmap1 + hmap2).

In your case, you could also just plot the transpose of your data-matrix and then split by rows, as follows (NB - the key parameter to use is split):

library(ComplexHeatmap)

set.seed(123)

mat=matrix(rnorm(100), 10)

foo=sample(letters[1:2], 10, replace=TRUE)

colnames(mat)=sapply(letters[1:10], function(x) paste(rep(x, 10), collapse=""))

cn = colnames(mat)

ha2 = rowAnnotation(foo=foo,
                #cn=anno_text(cn, rot=0, just="right", which="row"),
                annotation_height=unit.c(unit(5, "mm"), max_text_width(cn)))

draw(Heatmap(t(mat), split=foo, show_row_names=TRUE) + ha2, heatmap_legend_side="left", annotation_legend_side="left")

hmap

ADD COMMENTlink modified 8 months ago • written 8 months ago by Kevin Blighe21k
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: 1364 users visited in the last hour