0

I'm looking to figure out how to use the pheatmap package and to make a continuous color coded heatmap.

I would like to use three colors, red, white and blue to for my map, where white = 0, blue is for negative numbers, and red for positive. I want it such that it would be continuous, rather than anything being 0 = white, and positive being red, but more of a transition from a solid red to lighter fades until white.

I couldnt find it in the documentation, so perhaps it is my lack of understanding on how to get it to work.

Here is my code currently.

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = c("blue", "white", "red"),
  angle_col = 90)

Thank you!

SpiderK
  • 55
  • 6

1 Answers1

1

You could just supply a long vector of transitioning colours using colorRampPalette:

set.seed(1)
heatmap_matrix <- matrix(rnorm(400), nrow = 20)

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = colorRampPalette(c("blue", "white", "red"))(100),
  angle_col = 90)

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thats a good idea! Thank you! Unfortunately, I get this error: Error in seq.default(min(x, na.rm = T), max(x, na.rm = T), length.out = n + : attempt to apply non-function Any thoughts on how to approach this? – SpiderK Feb 28 '22 at 17:50
  • 1
    @SpiderK do you get the error if you cut and paste my code exactly? – Allan Cameron Feb 28 '22 at 17:52