0

I have a file that contains the cluster results. I created a heatmap in R by the following code.How to change the color of heatmap to red and green

nba <- read.csv("E:/clus.arff", sep=",")
nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, col = cm.colors(256), scale="column", margins=c(5,10))
user3663547
  • 11
  • 1
  • 1
  • 5

1 Answers1

1

You are using the cm.color palette which is a cyan-purple palette.

You can create your own palette for instance using RColorBrewer.

RColorBrewer provides a red-yellow-green palette you can use

library(RColorBrewer)
pal <- colorRampPalette(brewer.pal(11, "RdYlGn"))(100)

brewer.pal loads the palette (the palette has 11 colors, we're gonna use them all) and then colorRampPalette interpolates it to 100 colors.

Alternatively you can define your own colors:

redgreen <- c("red", "green") 
pal <- colorRampPalette(redgreen)(100)

After creating the palette just use it as the col parameter to heatmap.

nico
  • 50,859
  • 17
  • 87
  • 112