title: heatmap with values (ggplot2)--how to make cells square and automatically sized?
body: <p>This code for a heatmap, is from a previous answer here. I've changed it so it displays four decimal places:</p>
  
  <p><a href="https://stackoverflow.com/questions/14290364/heatmap-with-values-ggplot2" title="Previous Answer">Previous Answer</a></p>
  
  <pre><code>library(tidyverse)
  ## make data
  dat &lt;- matrix(rnorm(100, 3, 1), ncol=10)
  
  ## reshape data (tidy/tall form)
  dat2 &lt;- dat %&gt;%
    tbl_df() %&gt;%
    rownames_to_column('Var1') %&gt;%
    gather(Var2, value, -Var1) %&gt;%
    mutate(
      Var1 = factor(Var1, levels=1:10),
      Var2 = factor(gsub("V", "", Var2), levels=1:10)
    )
  
  ## plot data
  ggplot(dat2, aes(Var1, Var2)) +
    geom_tile(aes(fill = value)) + 
    geom_text(aes(label = round(value, 4))) +
    scale_fill_gradient(low = "white", high = "red")
  </code></pre>
  
  <p>With four decimal places my output looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/Bsxir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bsxir.png" alt="enter image description here"></a></p>
  
  <p>How can I:</p>
  
  <ol>
  <li>Make the cells large enough to contain all of the digits</li>
  <li>Make the cells square, i.e. not rectangular (so that they look like the output in the original answer)</li>
  <li>Force the display of significant digits so that say 0.9 displays as 0.9000</li>
  </ol>
  
  <p>Thank you.</p>