title: Common legend for a grid plot
body: <p>In this reproducible example grid plot, 3 plots have 3 fill colours, and z displays with the "col" blue, but in the fourth plot there is only 1 "col", so z displays as red.</p>
  
  <p>I want to show only one common legend (which I can do), <strong>but I want z to be blue in all four plots.</strong>. Is there a simple way to do that?</p>
  
  <p><a href="https://i.stack.imgur.com/JWLko.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JWLko.jpg" alt="enter image description here"></a></p>
  
  <pre><code>#---------------------
  # Reproducible example
  #---------------------
  library(tidyverse)
  library(ggplot2)
  library(grid)
  library(gridExtra)
  d0 &lt;- read_csv("x, y, col\na,2,x\nb,2,y\nc,1,z")
  d1 &lt;- read_csv("x, y, col\na,2,x\nb,2,y\nc,1,z")
  d2 &lt;- read_csv("x, y, col\na,2,x\nb,2,y\nc,1,z")
  d3 &lt;- read_csv("x, y, col\na,2,z\nb,2,z\nc,1,z")
  p0 &lt;- ggplot(d0) + geom_col(mapping = aes(x, y, fill = col))
  p1 &lt;- ggplot(d1) + geom_col(mapping = aes(x, y, fill = col))
  p2 &lt;- ggplot(d2) + geom_col(mapping = aes(x, y, fill = col))
  p3 &lt;- ggplot(d3) + geom_col(mapping = aes(x, y, fill = col))
  grid.arrange(p0, arrangeGrob(p1,p2,p3, ncol=3), ncol=1)
  </code></pre>