This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Color key in heatmap.2 function in R

The below image shows the type of the heatmap i want. As you can see the color key range in the heatmap is -3,3,9,15. How to achieve the same?

I have tried the break argument in the heatmap.2() function. But the color range keeps changing from what ever break i provide. I need the exact numbers in the color key as seen in the picture.

enter image description here

r

1 answer

Consider switching to ComplexHeatmap. It eliminates a lot of the problems one faces with heatmap.2 or pheatmap or any of those complicated heatmap building packages.

Even in ComplexHeatmap package, when I use the

colorRamp2(c(-3,3,9,15), c(“red”,”yellow”,”green”,”blue”))

The color range is still getting divided in the heatmap automatically to 15,10,5,0,-5. I basically want to see only the values (-3,3,9,15) in the color range bar.

You may want to look at advanced parameters or limit the data range to your specific range by trimming all values that fall outside the range.

Log in to answer this question.