title: How to assign your color scale on raw data in heatmap.2()
body: <p>I have data that looks like this:</p>
  
  <pre><code>                         Name    h1    h2    h3    h4    h5
  1            1420468_at_Asb17 0.000 2.328 0.000 0.000 0.000
  2    1430261_at_1700024J04Rik 1.236 2.050 0.000 0.000 0.000
  3           1431788_at_Fabp12 0.000 2.150 0.000 0.000 0.587
  4    1433187_at_B230112I24Rik 0.000 2.240 1.343 0.000 1.383
  5        1434430_s_at_Adora2b 0.000 2.006 1.459 0.000 1.272
  6           1435217_at_Gm7969 0.727 2.350 1.494 0.976 0.000
  7          1436717_x_at_Hbb-y 0.000 2.712 0.000 0.000 0.000
  8            1440859_at_Akap6 0.000 2.053 0.000 0.000 1.840
  9              1442625_at_--- 0.000 2.064 1.173 0.000 1.035
  10           1443715_at_Rbm24 0.969 2.219 0.000 0.000 0.000
  11             1445520_at_--- 0.000 2.497 0.000 0.000 0.000
  12          1446035_at_Gm7173 0.000 3.869 0.000 0.000 0.000
  13   1446597_at_6820445E23Rik 1.000 2.000 0.000 0.000 0.000
  14          1448925_at_Twist2 0.000 2.089 0.938 0.000 0.000
  15        1449711_at_Atp6v1e1 0.605 2.363 2.350 1.094 0.976
  16          1455931_at_Chrna3 0.000 2.354 0.000 0.000 0.000
  17 1457647_x_at_1600023N17Rik 0.000 2.734 0.000 0.000 1.812
  18             1458975_at_--- 0.000 2.079 0.000 0.000 0.000
  19             1459862_at_--- 0.727 2.606 0.000 0.000 1.151
  </code></pre>
  
  <p>Note in this data (and the actual one) there is no negative values and the positive values
  can be as large as 100 or so.</p>
  
  <p>What I want to do is to plot heat map with my own assigned color scale and scheme:</p>
  
  <ol>
  <li>When the value is 0 set it into white.</li>
  <li>When the value is == 1 set it into black.</li>
  <li>When the value is > 1 set it into shade of reds.</li>
  <li>When the value is &lt; 1 and > 0 set it into shade of greens.</li>
  </ol>
  
  <p>also without using any data scaling or built-in z-score transformation.
  How can I achieve that?</p>
  
  <p>My current code is this:</p>
  
  <pre><code>library(gplots)
  
  # Read data
  dat &lt;- read.table("http://dpaste.com/1501148/plain/",sep="\t",header=T);
  rownames(dat) &lt;- dat$Name
  dat &lt;- dat[,!names(dat) %in% c("Name")]
  
  # Clustering and distance measure functions
  hclustfunc &lt;- function(x) hclust(x, method="complete")
  distfunc &lt;- function(x) dist(x,method="maximum")
  
  #  Define colours
  hmcols &lt;- rev(redgreen(2750));
  
  # Plot 
  pdf("~/Desktop/tmp.pdf",height=10)
  heatmap.2(as.matrix(dat),Colv=FALSE,dendrogram="row",scale="row",col=hmcols,trace="none", margin=c(5,10), hclust=hclustfunc,distfun=distfunc,lwid=c(1.5,2.0),keysize=1);
  dev.off()
  </code></pre>
  
  <p>Which produces the following plot, where it uses the default z-score row scaling.</p>
  
  <p><img src="https://i.stack.imgur.com/1NEsq.jpg" alt="enter image description here"></p>