gpt4 book ai didi

r - ComplexHeatmap,无法创建水平图例

转载 作者:行者123 更新时间:2023-12-02 14:56:04 25 4
gpt4 key购买 nike

您好,我正在使用 ComplexHeatmap 包并遵循了他们的小插图,但是出于某种原因,我似乎无法强制图例变为水平。所以例如这里是一个例子,

set.seed(123)
library(ComplexHeatmap)
mat = matrix(rnorm(80, 2), 8, 10)
mat = rbind(mat, matrix(rnorm(40, -2), 4, 10))
rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)

ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep("a", 5), rep("b", 5))),
col = list(type1 = c("a" = "red", "b" = "blue")),
annotation_legend_param = list(type1 = list(
title_gp = gpar(fontsize = 16),
legend_direction = "horizontal", labels_gp = gpar(fontsize = 8)))
)



ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha_column)
draw(ht1, heatmap_legend_side = "right")

所以尽管添加了 legend_direction = "horizo​​ntal" 我仍然在这里得到这个,enter image description here

最佳答案

如果你需要水平绘制热图图例并且在热图底部,你可以使用这个解决方案:

ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha_column, 
heatmap_legend_param = list(
legend_direction = "horizontal",
legend_width = unit(5, "cm")
)
)
draw(ht1, heatmap_legend_side = "bottom")

enter image description here

否则,如果您需要在热图的顶部水平绘制(离散的)注释图例,您可以在 annotation_legend_param 中使用 nrow=1:

ha_column = HeatmapAnnotation(df = data.frame(type1 = c(rep("a", 5), rep("b", 5))),
col = list(type1 = c("a" = "red", "b" = "blue")),
annotation_legend_param = list(
type1 = list(
title_gp = gpar(fontsize = 16),
labels_gp = gpar(fontsize = 8),
nrow=1)))


ht1 = Heatmap(mat, name = "ht1", column_title = "Heatmap 1", top_annotation = ha_column)
draw(ht1, annotation_legend_side = "top")

enter image description here

关于r - ComplexHeatmap,无法创建水平图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52794692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com