Search code examples
rheatmappheatmap

how to reverse the color of row legend in heatmap?


I would like to reverse the default annotation for row:

library(NMF) #any other packages for this task are welcome
car<-cars
car$p<-sample(1:600, 50)*0.0001
aheatmap(as.matrix(cars[,1:2,drop=FALSE]),annRow =car[,"p",drop=FALSE])

enter image description here

As you can see in row annotation, the 0 represents white color and larger number the deeper green. I would like to see the smaller p, the deeper green (or grey).

Moreover, if that is possible, the p larger than 0.05 would present only white color.

It is really challenging for me. Thanks for any helps or comments


Solution

  • You can change the colors using the annColors parameter. This reverses the order of green-white:

    aheatmap(as.matrix(cars[,1:2,drop=FALSE]),annRow =car[,"p",drop=FALSE], annColors="-Greens")
    

    To make anything above p=.05 white, you could subset your data to make anything above that value NA and do the same coloring:

    car$p[car$p>.05]<-NA
    aheatmap(as.matrix(cars[,1:2,drop=FALSE]),annRow =car[,"p",drop=FALSE], annColors="-Greens")
    

    enter image description here