ComplexHeatmap 更改 rowAnnotation 中段/链接的方向

问题描述 投票:0回答:1

我正在构建一个大型热图并添加了行注释。这个特定的注释必须位于热图的左侧,但是当我添加标签时,段/链接面向错误的方向。有人可以帮我弄清楚如何翻转标签和注释之间的段吗?

可重现的示例:

library(ComplexHeatmap)

mat <- matrix(sample(c(-1, 0, 1), 30, replace = T), nrow = 10, ncol = 3, dimnames = list(letters[1:10], c(LETTERS[1:3])))
labels <- c(1:10)

set.seed(123)
anno <- anno_mark(at = labels, 
                  labels = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), 
                  which = "row")
foo <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")

ha = rowAnnotation(mark = anno, 
                   foo = foo, 
                   col = list("a" = "#440154FF", "b" = "#471365FF", "c" = "#482374FF", 
                              "d" = "#46337EFF", "e" = "#424186FF", "f" = "#3C4F8AFF", 
                              "g" = "#365C8DFF", "h" = "#31688EFF", "i" = "#2C738EFF", 
                              "j" = "#277F8EFF"), 
                   show_legend = FALSE)

ht1 = Heatmap(mat, 
              name = "Example", 
              heatmap_legend_param = list(color_bar = "continuous", at = c(-1, 0, 1), 
                                          labels = c("-1", "0", "1"),
                                          legend_width = unit(15, "cm"), 
                                          labels_gp = gpar(fontsize = 22),
                                          title_gp = gpar(fontsize = 22),
                                          title_position = "topleft",
                                          direction = "horizontal"),
              cluster_rows = F, 
              cluster_columns = T, 
              show_row_names = F,
              show_column_names = F,
              use_raster = F,
              left_annotation = ha
)

png(paste0("./",format(Sys.Date(), "%Y%m%d"), "_example.png"), width = 8, height = 4, units = "in", res = 600)
draw(ht1, heatmap_legend_side = "bottom", padding = unit(c(1, 1, 1, 1), "cm"))
dev.off()

这是结果图:

我只是想将最左侧的段移动到字母和注释框之间。

谢谢!

r heatmap complexheatmap
1个回答
0
投票

我找到了这个问题的答案;我只是错过了在

side
中指定
anno_mark()
参数。解决方案如下:

anno <- anno_mark(at = labels, 
              labels = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), 
              which = "row", side = "left")

© www.soinside.com 2019 - 2024. All rights reserved.