title: Plotting the maximum of a raster stack in R with specific colours
body: <p>I have a raster stack of 5 rasters (invented examples here in s), and I would like to make two plots of the max and min value from this stack- this is fairly simple using max/ min (a). </p>
  
  <pre><code> r &lt;- raster(nrows=10,ncols=100)
   r[] &lt;- rnorm(1000)
   s &lt;- stack(r,r,r,r,r) 
   a&lt;-max(s, na.rm=T)
   plot(a)   
  </code></pre>
  
  <p>However, what I want to do is plot but apply raster specific colours. So for example if the max value in a cell was from raster 3 in the stack, that cell in the plot would be coloured red, in the next cell the max value is from raster 5 then that would be green etc... Is there anyway of applying raster specific colours to such a raster stack plot?</p>
  
  <p>I'm sure this is fairly simply, but I'm going around in circles. If anyone has got any ideas I would be very grateful.</p>