title: Why does the `layout` I set lost its configuration after plotting a raster layer?
body: <p>I am doing an arrange of four maps for a report. My desire plots' design is this:
  <a href="https://i.stack.imgur.com/SgsEx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SgsEx.png" alt="enter image description here" /></a></p>
  <p>To do this, I use <code>layout()</code> and <code>plot</code> following guidelines <a href="https://www.benjaminbell.co.uk/2018/02/creating-multi-panel-plots-and-figures.html" rel="nofollow noreferrer">here</a>.</p>
  <p>I share below the code I am using to get what I mentioned. Note: code for plots 1 and 2 is simplified in order to focus on my question.</p>
  <p>First, I design my arrange of plots:</p>
  <pre><code>## Layout design ####
  
  layout(mat = matrix(c(1, 1, 1, 2, 2, 2, 2, 2,
                        3, 3, 3, 3, 4, 4, 4, 4),
                      ncol = 8, byrow=TRUE), 
         widths = c(1, 1, 1),
         heights = c(1))
  par(mar = c(0.5, 0.5, 0.5, 0.5),oma = c(1.5, 1.5, 1.5, 1.5))          
      
  layout.show(4) # With this command we see the current plots' design, which gives the same plot I shared previously.
  </code></pre>
  <p>Then, I start to plot:</p>
  <pre><code>## Set colours for maps ####
  
  col.t &lt;- &quot;#D2B48C&quot; # Coastal line colour
  col.amp &lt;- c(&quot;darkolivegreen2&quot;, &quot;olivedrab&quot;) # Marine protected area colour
  col.mar &lt;- &quot;lightskyblue&quot; # Sea colour
  
  ## First plot ####
  
  plot(1, xlim = xlim.1, ylim = ylim.1, axes = FALSE, ann = FALSE)
  rect(xleft = par(&quot;usr&quot;)[1], xright = par(&quot;usr&quot;)[2], ybottom = par(&quot;usr&quot;)[3], ytop = par(&quot;usr&quot;)[4], col = col.mar, border = &quot;transparent&quot;)
  plot(coastal_line, add = TRUE, col = col.t) #shape file
  
  ## Second plot ####
  
  plot(1, xlim = xlim.2, ylim = ylim.2, axes = FALSE, ann = FALSE)
  rect(xleft = par(&quot;usr&quot;)[1], xright = par(&quot;usr&quot;)[2], ybottom = par(&quot;usr&quot;)[3], ytop = par(&quot;usr&quot;)[4], col = col.mar, border = &quot;transparent&quot;)
  plot(coastal_line, add = TRUE, col = col.t) #shape file
  
  ## Third plot ####
  
  plot(1, xlim = xlim.3, ylim = ylim.3, axes = FALSE, ann = FALSE)
  rect(xleft = par(&quot;usr&quot;)[1], xright = par(&quot;usr&quot;)[2], ybottom = par(&quot;usr&quot;)[3], ytop = par(&quot;usr&quot;)[4], col = col.mar, border = &quot;transparent&quot;)
  
  plot(bathymetry, 
       col = fields::tim.colors(50), 
       xlim = c(par(&quot;usr&quot;)[1], par(&quot;usr&quot;)[2]), 
       ylim = c(par(&quot;usr&quot;)[3], par(&quot;usr&quot;)[4]),
       add=TRUE,
       legend=FALSE)  #raster file
  </code></pre>
  <p>So far, everything is ok and my arrange of plots look like this:
  <a href="https://i.stack.imgur.com/BCKEX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BCKEX.png" alt="enter image description here" /></a></p>
  <p>However, when I add the isobaths I get problems:</p>
  <pre><code>contour(bathymetry, 
          add = TRUE, 
          levels = seq(0, -80, -8))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/dC88E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dC88E.png" alt="enter image description here" /></a></p>
  <p>As you can see, the isobaths are plotted in a small region of my arrange of plots (in the left below corner). If I use <code>layout.show(n)</code>, I see the current arrange of plots design.</p>
  <pre><code>layout.show(16) # Here I use 16 because I checked that I had 16 plots in my layout
  </code></pre>
  <p><a href="https://i.stack.imgur.com/4yjYk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4yjYk.png" alt="enter image description here" /></a></p>
  <p>So, I don't know why, but after plotting the raster layer, my <code>layout</code> configuration (4 plots in a 2x2 matrix) has changed to a 2x8 matrix (=16 plots).</p>
  <p>Does anyone know why is this happening?</p>
  <p>Thanks in advance</p>