How to make the fill color in anno_barplot a gradient color like in heatmap
Hello, I am trying to make a barplot annotation. The values are between -1 and 1 and I would like to make the filling color gradient like in heatmap using colorRamp2(c(-1, 0, 1), c("green", "white", "red")), but it didn't work If I specify in
Signature = anno_barplot(sinfo %>% pull(Signature), height = unit(1.2, "cm"), gp = gpar(fill = colorRamp2(c(-1, 0, 1), c("green", "white", "red"))))
Do you have any suggestions? The purpose is to color the following barplots in gradient.

Thank you very much!
You can first generate a color mapping function:
col_fun = colorRamp2(c(-1, 0, 1), c("green", "white", "red"))
then you can generate colors with this function:
anno_barplot(x, gp = gpar(fill = col_fun(x)))
Thank you for this workaround. I'm also trying to combine anno_barplot as a gradient on top of another HeatmapAnnotation object. I tried the above example using col_fun function but for some reason, it doesn't work. Here's my code and output:
col_fun <- colorRamp2(c(min(tblim151$G15score),0,max(tblim151$G15score)), c("skyblue","linen","red1"))
ha3 = HeatmapAnnotation("G15score" = anno_barplot(tblim151$G15score, gp=gpar(col_fun(tblim151$G15score))), height = unit(20, "mm"))
ha2 = HeatmapAnnotation(df=data.frame(tblim151[,c(93,91,94,13,15,8,11,9,10,17)]), col = ann_colors151, simple_anno_size = unit(4, "mm"), show_legend = T,annotation_name_gp = gpar(fontsize = 8))
I combined my column annotations within Heatmap() using,
top_annotation = c(ha3,ha2)
Your help is appreciated!