2

I would like to draw a heatmap of an interrelationship matrix to show the distance from 1.

I have made a heatmap as below, but I would like to have the colour defined according to the distance from 1; the further the number, the lighter the color would be.

library(pheatmap)
pheatmap(Interrelation, cluster_rows = FALSE, cluster_cols = FALSE)

M--
  • 25,431
  • 8
  • 61
  • 93
Lisa
  • 251
  • 1
  • 13

1 Answers1

1

This is an example with colors ranging from "darkblue" to "lightblue" with darker colors assigned to median of mtcars dataset.

library(pheatmap)

#you can decrease 0.5 if you want finer palette
my_colors <- seq(min(mtcars),max(mtcars), by=0.5) 

my_palette <- c(colorRampPalette(colors=c("lightblue","darkblue"))(n=(length(my_colors)-1)/2),
                "darkblue",
                colorRampPalette(colors=c("darkblue","lightblue"))(n=(length(my_colors)-1)/2))

pheatmap(mtcars,  
         scale = "none",         
         cluster_cols=FALSE,    
         cluster_rows = FALSE,
         treeheight_row=0,      
         show_rownames=FALSE,   
         main = "Example",
         color = my_palette,
         breaks = my_colors)

M--
  • 25,431
  • 8
  • 61
  • 93