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:
- 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")
- 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")
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"))
To plot the rowAnnotation on the left, you need:
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