This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Adding a continuous "wrap around" scale to heat map

I am aiming to create a heatmap similar to the one below.

enter image description here

I have successfully generated one that is satisfactory EXCEPT for the color scale (below). I used the code:

heatmap(Hallmark3, Colv = NA, Rowv = NA, scale="column", cexRow=.8, cexCol=1)

enter image description here

The coloring must indicate time of day so I would like it to be continuous and depict 0-24hrs. This is what they have done in the first heat map. I will also need to figure out how to add a legend showing the scale where it starts at 0 and ends at 24 (marking every 6hrs as in the first image). I think maybe I might have to do something indicating the scale represents radians or something along those lines but I am lost on how to get there.

r heatmap

1 answer

Just use a symmetrical color palette and pass it into the col= argument.

pal <- colorRampPalette(c('blue', 'brown', 'blue'))
plot(1:50, rep(1,50), col=pal(50), pch=16)

heatmap(..., col=pal(100))

The color bar needs to be added separately with a legend call, or you can switch to a more complete heatmap package such as ComplexHeatmap, Superheat or many others that add the color bar automatically.

Thank you so much. That was very helpful :)

Log in to answer this question.