title: How to plot legend in place of a plot multiple plots per window in R
body: <p>I want to place a common legend for my three plots in the slot where the fourth plot would go (highlighted in yellow). How can I do this?</p>
  <p><strong>Code to reproduce plots</strong></p>
  <pre><code>par(mfrow = c(2, 2))
  
  x &lt;- rep(1:9, 3)
  y &lt;- sample(1:9, 27, replace = T)
  group &lt;- rep(1:3, each = 9)
  
  for(i in 1:3){
    plot(x = x, y = y, type = &quot;n&quot;)
    for(j in 1:3){
      print(c(&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;)[group])
  
      lines(x = x[group == j],
            y = y[group == j],
            col = c(&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;)[j])
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/eVRzf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eVRzf.png" alt="enter image description here" /></a></p>