title: Overlaying multiple geom_tile plots in ggplot2
body: <p>First question from me, hope it's phrased correctly. I couldn't find anything on this so I'll bite the bullet.</p>
  
  <p>I'd like to create a <code>geom_tile</code> plot in which for each combination of <code>x</code> and <code>y</code>, I have 5 variables for the <code>z</code> that all sum to one. I'd like the colour of the square for each <code>x-y</code> combination to reflect which <code>z</code> number is largest. For example, imagine I have 5 <code>z</code> variables <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code> and <code>e</code>. If <code>a=1</code> and <code>b=c=d=e=0</code>, the square would be blue, if <code>b=1</code> and <code>a=c=d=e=0</code> it would be red, etc. If <code>a=b=0.5</code> and the others are zero, it would be an interpolated colour (i.e. purple). Perhaps even better, a crosshatch of red and blue, but I don't know if that is possible in <code>ggplot</code>.</p>
  
  <p>I am not sure how best to go ahead. I thought about plotting 5 <code>geom_tile</code> plots on top of each other, where each one is a different colour and the alpha is scaled by e.g. the value of a (so the cell is transparent when <code>a = 0</code> and strongly coloured when <code>a = 1</code>). There might also be a way to do it using  colour ramps, but I drew a blank there too.</p>
  
  <p>If anyone can see how to do this off the top of their head, I'd be much obliged. Here's a dataset of random numbers in the same format as my actual data.</p>
  
  <pre><code>rand &lt;- matrix(runif(50*50*5), ncol=5, nrow=50*50)
  rand &lt;- rand / apply(rand, 1, sum) # Make sure the numbers sum to one in each row
  d &lt;- data.frame(a = rand[,1],
                  b = rand[,2],
                  c = rand[,3],
                  d = rand[,4],
                  e = rand[,5],
                  expand.grid(x = 1:50, y = 1:50))
  </code></pre>
  
  <p>Update: By using the first answer from sebastian-c and my own dataset, I was able to make this figure. I obtained the colours using the function brewer.pal(5,"Spectral") in the package RColorBrewer. Needs a custom legend, but otherwise I am pretty happy with it. The solid colours show pure "Evolutionarily stable strategies" (ESS; i.e. strategies that cannot be beaten by a mutant strategy). Areas of overlapping colours show mixed ESS, in which the equilibrium is a stable balance of two or more strategies.</p>
  
  <p><img src="https://i.imgur.com/qwASFBW.png" alt="Overlapped geom_tile plots ESS"></p>