I am currently creating a heatmap for some data where the values for each item (OTU) vary greatly, so I am using the scale="row"
option.
I assumed that this would utilise the same colour gradient for each row so the maximum colour would always be present (dark green), as would the minimum (white). However as you can see below some go from white, others from a light green, and go to a dark or darkish green.
Here is the code I have been using:
library(gplots)
library(RColorBrewer)
data <-read.csv("Heatmap_data.csv", comment.char="#")
rnames <- data[,1] # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)]) # transform column 2-5 into a matrix
rownames(mat_data) <- rnames # assign row names
my_palette <- colorRampPalette(c("white", "dark green"))(n = 1090)
heatmap(mat_data, Rowv=NA, Colv=NA, col = my_palette, scale="row", margins=c(23,15))
Many of the values which are off-white are actually 0s as you can see in the data here:
MB.11 MB.8 MB.7 MB.12 MB.9 MB.10 MB.4 MB.6 MB.5 MB.3 MB.2 MB.1 K2295 K229456 K2299 K2297 K2298 K2293 K2294 K2292 K2290 K2291
OTU_43 23.5019505852 4.3947267864 6 18.3651985319 3.0748596382 5.5431848853 71.853471596 24.1857966978 12.6422018349 13.2893694289 46.5896990741 21.0355475222 38.5817456801 7.723156853 55.9703296703 6.1243646222 72.4165876777 74.0147572816 46.6683375104 87.3876576884 23.2358576642 33.7528164347
OTU_48 27.7750325098 36.4134505159 9 55.0955955956 9.7370555209 8.8690958165 108.8913435528 25.8199721504 23.8256880734 10.3060415979 42.7864583333 4.7020635638 3.6397873283 3.2518555171 69.8124542125 0 3.1146919431 26.7984466019 124.2201336675 355.7125809751 38.2267335766 63.8762977689
OTU_162 8.0120286086 11.3007260222 2 8.7714381048 2.5623830318 3.3259109312 35.5563570784 19.6101054307 12.6422018349 16.0014856388 57.0486111111 31.9245368278 4.367744794 3.2518555171 6.3192307692 3.8973229414 12.4587677725 29.3506796117 11.6670843776 35.8513467439 47.2212591241 45.3666887564
OTU_64 16.0240572172 0 36 35.6339673006 0.5124766064 5.5431848853 3.7037871957 0 1.4587155963 0 24.7210648148 0 1.4559149313 0 0 0 0 0 0 3.3610637572 0 2.1776010603
OTU_60 0 61.5261750096 23 0 42.0230817218 0 0 0 8.752293578 7.5939253879 3.8032407407 11.6314203946 21.8387239699 13.8203859476 8.1247252747 0 22.5815165877 0 3.4314954052 14.0044323219 8.2449817518 3.6293351005
OTU_116 136.7386215865 8.7894535728 15 30.9741408075 23.0614472863 103.6575573549 0 0 0 0 0 0 31.3021710235 8.1296387927 28.586996337 28.9515418502 49.83507109 0 0 0 0 0
OTU_86 7.477893368 26.3683607184 1 2.1928595262 21.5240174672 16.6295546559 2.9630297565 0.653670181 0 0 13.3113425926 0 0 0 0.3009157509 0 0 0 0 2.8008864644 0.7495437956 1.0888005302
OTU_534 134.0679453836 0 15 0 26.6487835309 180.1535087719 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_75 81.7226918075 0 6 0 12.2994385527 121.3957489879 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_176 26.7067620286 0 0 19.461628295 26.6487835309 9.423414305 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7.9845372211
Any help would be greatly appreciated!