I am trying to use ComplexHeatmap to plot heatmap with annotation. The code that I have tried


mat = matrix(rnorm(25), 5)
rownames(mat) = paste0("R", 1:5)
colnames(mat) = paste0("C", 1:5)

col_fun = colorRamp2(c(0, 2, 5), c("white", "blue", "red"))
data_foo = c(0.1, 3, 1.6, 2.8, 4)

ha = HeatmapAnnotation(which = "row", foo = data_foo, col = list(foo = col_fun))
Heatmap(mat, name = "mat", right_annotation = ha)

ha1 = HeatmapAnnotation(which = "row", foo = anno_text(data_foo))
Heatmap(mat, name = "mat", right_annotation = ha1)

Can I obtain the annotation with colors varying as per the annotation values and also display the values in the annotation? i.e is it possible to combine the annotation in both figures? HeatMap with color annotation

HeatMap with values as annotation


1 Answer 1


Answer from @haci, converted from comment:

You can use the pch parameter in anno_simple() but you can only use a single character or a digit. It is not limited to symbols only, you can provide a vector to pch, but only the first character would be printed. If by chance your values are [0-9] you can use pch as kind of hack for your purposes above.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.