title: Adding marginal totals to ggplot heatmap in R
body: <p>I want to add sum and row totals to my heatmap and struggling with already suggested ways to realize in other posts like here: <a href="https://stackoverflow.com/questions/39116838/ggplot2-independent-continuous-fill-for-summary-row-column">ggplot2: Independent Continuous Fill for Summary Row &amp; Column</a>.</p>
  
  <p>The problem with the above post is, that I do not understand the code where the totals (row, column) are created. Although it is marked as "# create the summary row &amp; column" I don't get it.</p>
  
  <p>So it would be great if...
   1. ...somebody could help me and show me a (simple) way to get there in reference to my posted code (below) and also 
   2. ...if the row- and column totals could have separate color scales.</p>
  
  <p>I tried this...</p>
  
  <pre><code># create sample
  scen &lt;- 1:32
  ls &lt;- rep(1:7, length(scen))
  df &lt;- data.frame(Landscape = ls, Scenario = scen)
  df$SoP &lt;- sample(seq(-0.070, 0.070, by = 0.01),replace=T, nrow(df))
  df$Landscape_Name &lt;- LETTERS[1:7]
  
  # create heatmap
  library(ggplot2)
  df.diff &lt;- ggplot(df, aes(x = Landscape_Name, y = Scenario)) +
    geom_tile(aes(fill = SoP)) +
    geom_text(size = 3, aes(label = round(SoP,2))) + #displays cell values
    scale_fill_gradient2(low = "gold", #colors
                         mid = "white",
                         high = "grey",
                         midpoint = 0) +
    theme(panel.grid.major.x=element_blank(), #no gridlines
          panel.grid.minor.x=element_blank(), 
          panel.grid.major.y=element_blank(), 
          panel.grid.minor.y=element_blank(),
          panel.background=element_rect(fill="white"),
          axis.text.x = element_text(angle=0, hjust = 0.5,vjust=0.5, size = 8,face = NULL),
          axis.text.y = element_text(size = 8,face = NULL),
          plot.title = element_text(size=10,face="bold")) +
    ggtitle("Treatment efficiency") + 
    theme(legend.title=element_text(face="bold", size=8)) + 
    scale_x_discrete(name="Landscape", position = "top") +
    scale_y_discrete(name="Scenario") +
    labs(fill="SoP")
  print(df.diff)
  </code></pre>
  
  <p>Thanks a lot for your help!</p>