title: heatmap with values (ggplot2)
body: <p>I've seen heatmaps with values made in various R graphics systems including lattice and base like this:</p>
  
  <p><img src="https://i.stack.imgur.com/qFgTK.png" alt="enter image description here"></p>
  
  <p>I tend to use <code>ggplot2</code> a bit and would like to be able to make a heatmap with the corresponding cell values plotted.  Here's the heat map and an attempt using <code>geom_text</code>:</p>
  
  <pre><code>library(reshape2, ggplot2)
  dat &lt;- matrix(rnorm(100, 3, 1), ncol=10)
  names(dat) &lt;- paste("X", 1:10)
  dat2 &lt;- melt(dat, id.var = "X1")
  p1 &lt;- ggplot(dat2, aes(as.factor(Var1), Var2, group=Var2)) +
      geom_tile(aes(fill = value)) +
      scale_fill_gradient(low = "white", high = "red") 
  p1
  
  #attempt
  labs &lt;- c(apply(round(dat[, -2], 1), 2, as.character))
  p1 +  geom_text(aes(label=labs), size=1)
  </code></pre>
  
  <p>Normally I can figure out the x and y values to pass but I don't know in this case since this info isn't stored in the data set.  How can I place the text on the heatmap?</p>