title: differences in heatmap/clustering defaults in R (heatplot versus heatmap.2)?
body: <p>I'm comparing two ways of creating heatmaps with dendrograms in R, one with <code>made4</code>'s <code>heatplot</code> and one with <code>gplots</code> of <code>heatmap.2</code>. The appropriate results depend on the analysis but I'm trying to understand why the defaults are so different, and how to get both functions to give the same result (or highly similar result) so that I understand all the 'blackbox' parameters that go into this.</p>
  
  <p>This is the example data and packages:</p>
  
  <pre><code>require(gplots)
  # made4 from bioconductor
  require(made4)
  data(khan)
  data &lt;- as.matrix(khan$train[1:30,])
  </code></pre>
  
  <p>Clustering the data with heatmap.2 gives:</p>
  
  <pre><code>heatmap.2(data, trace="none")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bNoTl.png" alt="enter image description here"></p>
  
  <p>Using <code>heatplot</code> gives:</p>
  
  <pre><code>heatplot(data)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/m25OG.png" alt="enter image description here"></p>
  
  <p>very different results and scalings initially. <code>heatplot</code> results look more reasonable in this case so I'd like to understand what parameters to feed into <code>heatmap.2</code> to get it to do the same, since <code>heatmap.2</code> has other advantages/features I'd like to use and because I want to understand the missing ingredients.</p>
  
  <p><code>heatplot</code> uses average linkage with correlation distance so we can feed that into <code>heatmap.2</code> to ensure similar clusterings are used (based on: <a href="https://stat.ethz.ch/pipermail/bioconductor/2010-August/034757.html" rel="noreferrer">https://stat.ethz.ch/pipermail/bioconductor/2010-August/034757.html</a>)</p>
  
  <pre><code>dist.pear &lt;- function(x) as.dist(1-cor(t(x)))
  hclust.ave &lt;- function(x) hclust(x, method="average")
  heatmap.2(data, trace="none", distfun=dist.pear, hclustfun=hclust.ave)
  </code></pre>
  
  <p>resulting in:
  <img src="https://i.stack.imgur.com/hGifd.png" alt="enter image description here"></p>
  
  <p>this makes the row-side dendrograms look more similar but the columns are still different and so are the scales. It appears that <code>heatplot</code> scales the columns somehow by default that <code>heatmap.2</code> doesn't do that by default. If I add a row-scaling to heatmap.2, I get:</p>
  
  <pre><code>heatmap.2(data, trace="none", distfun=dist.pear, hclustfun=hclust.ave,scale="row")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/fla6Y.png" alt="enter image description here"></p>
  
  <p>which still isn't identical but is closer. How can I reproduce <code>heatplot</code>'s results with <code>heatmap.2</code>? What are the differences?</p>
  
  <p><em>edit2</em>: it seems like a key difference is that <code>heatplot</code> rescales the data with both rows and columns, using:</p>
  
  <pre><code>if (dualScale) {
      print(paste("Data (original) range: ", round(range(data), 
          2)[1], round(range(data), 2)[2]), sep = "")
      data &lt;- t(scale(t(data)))
      print(paste("Data (scale) range: ", round(range(data), 
          2)[1], round(range(data), 2)[2]), sep = "")
      data &lt;- pmin(pmax(data, zlim[1]), zlim[2])
      print(paste("Data scaled to range: ", round(range(data), 
          2)[1], round(range(data), 2)[2]), sep = "")
  }
  </code></pre>
  
  <p>this is what I'm trying to import to my call to <code>heatmap.2</code>. The reason I like it is because it makes the contrasts larger between the low and high values, whereas just passing <code>zlim</code> to <code>heatmap.2</code> gets simply ignored. How can I use this 'dual scaling' while preserving the clustering along the columns? All I want is the increased contrast you get with:</p>
  
  <p><code>heatplot(..., dualScale=TRUE, scale="none")</code></p>
  
  <p>compared with the low contrast you get with:</p>
  
  <p><code>heatplot(..., dualScale=FALSE, scale="row")</code></p>
  
  <p>any ideas on this?</p>