title: Insert geom_sf layer underneath existing geom_sf layers
body: <p>I have a basic map of India with states and borders, some labels, and a number of other specifications stored as a gg object. I'd like to generate a number of maps with a district layer, which will bear data from different variables.</p>
  
  <p>To prevent the district maps overwriting state and country borders, it must be before all the previous code, which I'd like to avoid repeating. </p>
  
  <p>I thought I could do this by calling on <code>$layers</code> for the gg object as per <a href="https://stackoverflow.com/questions/20249653/insert-layer-underneath-existing-layers-in-ggplot2-object">this answer</a>. However, it throws an error. Reprex is below:</p>
  
  <pre><code>library(ggplot2)
  library(sf)
  library(raster)
  
  # Download district and state data (should be less than 10 Mb in total)
  
  distSF &lt;- st_as_sf(getData("GADM",country="IND",level=2))
  
  stateSF &lt;- st_as_sf(getData("GADM",country="IND",level=1))
  
  # Add border
  
  countryborder &lt;- st_union(stateSF)
  
  # Basic plot
  
  basicIndia &lt;- ggplot() +
    geom_sf(data = stateSF, color = "white", fill = NA) +
    geom_sf(data = countryborder, color = "blue", fill = NA) +
    theme_dark()
  
  basicIndia
  </code></pre>
  
  <p><img src="https://i.imgur.com/RlcI9uI.png" alt=""></p>
  
  <pre><code># Data-bearing plot
  
  districts &lt;- ggplot() +
    geom_sf(data = distSF, fill = "gold")
  
  basicIndia$layers &lt;- c(geom_sf(data = distSF, fill = "gold"), basicIndia$layers)
  
  basicIndia
  #&gt; Error in y$layer_data(plot$data): attempt to apply non-function
  </code></pre>
  
  <h1>Intended outcome</h1>
  
  <p><img src="https://i.imgur.com/Xq8hqvX.png" alt=""></p>
  
  <p>Any help would be much appreciated!</p>