ComplexHeatmap - how to change the position of the legend of rowAnnotation
1
0
Entering edit mode
AR3513 • 0
@ar3513-11025
Last seen 13 months ago

Hi

The position of the legend of rowAnnotation() is the right side of the heatmap. However, I would like to put it in the left side of the heatmap. Is that possible?

Also, how can I decrease the width of the annotation? I tried using the argument width (eg. width = unit(0.5, "mm")) but it didn't work

Any help?

Many thanks,

Andrea

ComplexHeatmap • 2.0k views
ADD COMMENT
0
Entering edit mode

To plot the rowAnnotation on the left, you need:

draw(hmap, annotation_legend_side = 'left', ...)

For the width [of the annotation], please confirm that you are trying in the same way as mentioned here: https://jokergoo.github.io/ComplexHeatmap-reference/book/more-examples.html

ADD REPLY
0
Entering edit mode
Zuguang Gu ▴ 210
@zuguang-gu-7797
Last seen 11 days ago
Germany / Heidelberg / DKFZ

Em, this something not very clear for users on the row annotation legends. As I mentioned in the ComplexHeatmap manual: "If the heatmaps are concatenated horizontally, all heatmap and row annotation legends are grouped and all column annotation legends are grouped. The reason is we assume the horizontal direction passes the main message of the plot, while the vertical direction provides secondary information." So you cannot separate legends for heatmaps and row annotations.

Can you also attach the code you are using? I believe there are some solutions for it. There are some I can think of is:

  1. First suppress the annotation legends, by setting show_legend = FALSE in rowAnnotation() function, and later manually construct one legend and assign it to annotation_legend_list argument. With this, you can control it by annotation_legend_side = "left". See following example:

m = matrix(rnorm(100), nrow = 10)
ha = rowAnnotation(foo = 1:10, show_legend = FALSE)
ht = Heatmap(m) + ha
lgd = color_mapping_legend(ha@anno_list[[1]]@color_mapping)
# you can also construct a Legend object by
lgd = Legend(title = "foo", 
    col_fun = circlize::colorRamp2(c(0, 10), c("white", "red")),
    at = seq(0, 10, by = 2))
draw(ht, annotation_legend_list = lgd, annotation_legend_side = "left")

image

  1. You can convert the row annotations to the left/right annotations to the heatmap. Now the vertical direction is the first major dimension of the heatmap list, and thus, legends for column annotations and heatmaps are grouped as the "heatmap legend" while the legends for row annotations are the "annotation legends" and they can be controlled by annotation_legend_side. Here the important thing is to add the Heatmap object by %v% to make it a vertical heatmap list. See the following example:

m = matrix(rnorm(100), nrow = 10)
ha = rowAnnotation(foo = 1:10)

ht = Heatmap(m, right_annotation = ha) %v% NULL  ## <<== here to make it vertical
draw(ht, annotation_legend_side = "left")

image

And for the width of the row annotation, I guess your row annotations are the "heatmap-like" annotations. This is called "simple annotation" in ComplexHeatmap, and you can control the width by :

rowAnnotation(..., simple_anno_size = unit(1, "cm"))
# or 
rowAnnotation(..., simple_anno_size_adjust = TRUE, width = unit(1, "cm"))
# or, I am not very sure
rowAnnotation(..., annotation_width = unit(1, "cm"))
ADD COMMENT

Login before adding your answer.

Traffic: 332 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