r-如何在ComplexHeatmap的连续色阶中创建颜色中断



我想用ComplexHeatmap包创建一个热图,其中我有一个连续的颜色刻度,最高可达某个阈值,并且对于阈值以上的值有一个可区分的颜色。我已尝试将阈值以上的值替换为最大值。这给了我热图想要的结果。然而,在这种情况下,我的色标图例不再准确。有没有一种方法可以为复杂的热图创建颜色中断,比如";breaks(("用于热图。2?此外,我可以在我的图例中包含na_col值吗?

对于添加NA颜色,我尝试添加一个额外的图例:

draw(myHeatmap)
NA_leg<-Legend(at = c(1), title = "", legend_gp = gpar(fill = "grey"), labels = c("NA"))
draw(NA_leg, x = unit(20, "cm"), y = unit(10, "cm"))

但是,在缩放或导出图像时,它不会停留在正确的位置。有没有办法固定相对于热图的位置?

我检查过,没有任何介于(-(0.8和(-(0.8001之间的值,并使用Heatmap((的col_fun参数更改了颜色。

col_fun<-colorRamp2(c(-0.8001,-0.8,0,0.8,0.8001), c("darkblue","skyblue","white", "brown1", "darkred"))
Heatmap(matrix, show_row_dend = F, show_column_dend = F, na_col = "grey", cluster_rows = F, cluster_columns = F,
show_row_names = F, show_column_names = F, cluster_row_slices = F, cluster_column_slices = F,
heatmap_legend_param = list(title = "legend", at = c(-1,-.5, 0, 0.5, 1), 
labels = c("<-0.8","" ,"0","", ">0.8")), column_title_gp = gpar(fontsize = 10), row_title_gp = gpar(fontsize = 10), col = col_fun)

对于在图例中包括NA的问题,我使用";annotation_legend_list";在draw函数中:

myHeatmap<-Heatmap(matrix, col = col_fun, show_heatmap_legend = F, show_row_dend = F, show_column_dend = F, na_col = "grey", cluster_rows = F, cluster_columns = F,
show_row_names = F, show_column_names = F, cluster_row_slices = F, cluster_column_slices = F,
column_title_gp = gpar(fontsize = 10), row_title_gp = gpar(fontsize = 10))
#create legend
main_leg<-Legend(at = c(-1,-.5, 0, 0.5, 1), col_fun =  col_fun, title = "my_title",
labels = c(expression("" <= -0.8),"" ,"0","", expression("">=0.8)), title_position = "leftcenter-rot")
NA_leg<-Legend(at = c(1), title = " ", legend_gp = gpar(fill = "grey"), labels = c("NA"), title_position = "leftcenter-rot")
draw(myHeatmap, column_title = "my Title", annotation_legend_list = list(main_leg, NA_leg))

相关内容

  • 没有找到相关文章

最新更新