ComplexHeatmap 在 rowAnnotation 中更改 segment/link 的方向
ComplexHeatmap change direction of segment/link in rowAnnotation
我正在构建一个大型热图并添加了行注释。这个特定的注释必须在热图的左侧,但是当我添加标签时,segment/link 朝向错误的方向。谁能帮我弄清楚如何将片段翻转到标签和注释之间?
可重现的例子:
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()
这是结果图:
我只是想将最左边的线段移动到字母和注释框之间。
谢谢!
我找到了答案:我只是错过了向 anno_mark 添加辅助参数,如下所示:
anno <- anno_mark(at = labels,
labels = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
which = "row", side = "left)
我正在构建一个大型热图并添加了行注释。这个特定的注释必须在热图的左侧,但是当我添加标签时,segment/link 朝向错误的方向。谁能帮我弄清楚如何将片段翻转到标签和注释之间?
可重现的例子:
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()
这是结果图:
我只是想将最左边的线段移动到字母和注释框之间。
谢谢!
我找到了答案:我只是错过了向 anno_mark 添加辅助参数,如下所示:
anno <- anno_mark(at = labels,
labels = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
which = "row", side = "left)