Combine plots that have a legend with one that doesn't
<p>I can combine three plots that don't have any legends, but when I add legends to two of the plots I can't combine them. How can I combine some plots with legends with a plot without a legend?</p>

<p>Here's an example of how I'm combining plots without legends:</p>

<pre><code>library(ggplot2)
map_data &lt;- data.frame(lon = c(-177.5, -172.5, -167.5, -162.5, -157.5, -152.5),
                       lat = c(87.5, 87.5, 87.5, 87.5, 87.5, 87.5),
                       ssta = c(-2.78999996, 0.09999999,  0.19999999,  0.06000000,  1.65999997, -0.41000000))

# one map
p.1 &lt;- ggplot() + 
    borders("world", 
          colour="black", 
          fill="white") +
  geom_tile(data = map_data,
            aes(lon,
                lat)) + # no fill value so no legend
  coord_fixed() + 
  scale_fill_viridis(na.value = "transparent") +
  theme_minimal() 

# a second map, the same general shape
p.2 &lt;- p.1

# a line plot
library(lubridate)
time_sequence &lt;-  seq(dmy("01-01-1800"), 
                      dmy("01-01-1960"), 
                      by = 'month')
long_plot_data &lt;- data.frame(variable = seq(dmy("01-01-1800"), 
                                            dmy("01-01-1960"), 
                                            by = 'month'),
                             value = runif(length(time_sequence)),
                             col = runif(length(time_sequence)))

p.3 &lt;-  ggplot(long_plot_data, 
              aes(variable, 
                  value)) +
  geom_line() +
  theme_minimal()


# combine plots
library(grid)
grid.newpage()
grid.draw(rbind(ggplotGrob(p.1), 
                ggplotGrob(p.2),
                ggplotGrob(p.3),
                size = "last"))
</code></pre>

<p><a href="https://i.stack.imgur.com/mlG47.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mlG47.png" alt="enter image description here"></a></p>

<p>And now if I add a fill value to the map plots, I get a legend, and an error when I try to combine in the same way:</p>

<pre><code># one map
p.1 &lt;- ggplot() + 
    borders("world", 
          colour="black", 
          fill="white") +
  geom_tile(data = map_data,
            aes(lon,
                lat,
                fill = ssta)) + # gives a legend
  coord_fixed() + 
  scale_fill_viridis(na.value = "transparent") +
  theme_minimal() 
</code></pre>

<p>Here's what this looks like:</p>

<p><a href="https://i.stack.imgur.com/2rlWj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2rlWj.png" alt="enter image description here"></a></p>

<pre><code># a second map, the same general shape
p.2 &lt;- p.1

# a line plot
library(lubridate)
time_sequence &lt;-  seq(dmy("01-01-1800"), 
                      dmy("01-01-1960"), 
                      by = 'month')
long_plot_data &lt;- data.frame(variable = seq(dmy("01-01-1800"), 
                                            dmy("01-01-1960"), 
                                            by = 'month'),
                             value = runif(length(time_sequence)),
                             col = runif(length(time_sequence)))

p.3 &lt;-  ggplot(long_plot_data, 
              aes(variable, 
                  value)) +
  geom_line() +
  theme_minimal()
</code></pre>

<p>Now I try to combine the two maps with legends and the line plot without a legend:</p>

<pre><code># combine plots
library(grid)
grid.newpage()
grid.draw(rbind(ggplotGrob(p.1), 
                ggplotGrob(p.2),
                ggplotGrob(p.3),
                size = "last"))
</code></pre>

<p>The output is <code>Error: ncol(x) == ncol(y) is not TRUE</code></p>

<p>But if I add a legend to the line plot, so that all three plots have legends, I can combine them:</p>

<pre><code>p.3 &lt;-  ggplot(long_plot_data, 
              aes(variable, 
                  value, 
                  colour = col)) +
  geom_line() +
  theme_minimal()


# combine plots
library(grid)
grid.newpage()
grid.draw(rbind(ggplotGrob(p.1), 
                ggplotGrob(p.2),
                ggplotGrob(p.3),
                size = "last"))
</code></pre>

<p><a href="https://i.stack.imgur.com/IArDg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IArDg.png" alt="enter image description here"></a></p>

<p>How can I combine two plots with legends with one without a legend?</p>