R 如何在ComplexHeatmap的连续颜色比例中创建分色?

R 如何在ComplexHeatmap的连续颜色比例中创建分色?,r,heatmap,R,Heatmap,我想用ComplexHeatmap包创建一个热图,其中我有一个连续的颜色比例,可以达到某个阈值,对于阈值以上的值,我有一个distinkt颜色。我尝试用最大值替换阈值以上的值。这为我提供了热图所需的结果。然而,在这种情况下,我的色阶图例不再准确。有没有一种方法可以为复杂的热图创建分色,比如“breaks()”对热图的作用。2? 此外,我可以在我的图例中包含na_col值吗 为了添加NA颜色,我尝试添加一个额外的图例: draw(myHeatmap) NA_leg<-Legend(at =

我想用ComplexHeatmap包创建一个热图,其中我有一个连续的颜色比例,可以达到某个阈值,对于阈值以上的值,我有一个distinkt颜色。我尝试用最大值替换阈值以上的值。这为我提供了热图所需的结果。然而,在这种情况下,我的色阶图例不再准确。有没有一种方法可以为复杂的热图创建分色,比如“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"))
draw(我的热图)

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


col\u fun欢迎来到SO!您应该发布到目前为止的代码,以及一些数据,以便我们运行代码。查看用于发布数据的
dput
功能。
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)
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))