title: whole earth polygon for world map in ggplot2 (and sf)
body: <p>When plotting world maps there is a problem with <code>ggplot2</code>: it colours the whole background with the same colour, including the corners of the plot which aren't actually part of the globe, see the snapshot below produced by the following code (it uses bleading edge <code>sf</code> abd <code>ggplot2</code> versions but the issue is generic, see the blog post mentioned below):</p>
  
  <pre><code>    #install.packages("devtools")
      #devtools::install_github("tidyverse/ggplot2")
      #devtools::install_github("edzer/sfr")
  
      library(ggplot2)
      library(sf)
      library(rnaturalearth)
      library(dplyr)
  
      theme_map &lt;- function(...) {
        theme_minimal() +
        theme(
          text = element_text(family = "Ubuntu Regular", color = "#22211d"),
          axis.line = element_blank(),
          axis.text.x = element_blank(),
          axis.text.y = element_blank(),
          axis.ticks = element_blank(),
          axis.title.x = element_blank(),
          axis.title.y = element_blank(),
          panel.grid.minor = element_line(color = "#ebebe5", size = 0.2),
          panel.grid.major = element_line(color = "#ebebe5", size = 0.2),
          plot.background = element_rect(fill = "#f5f5f2", color = NA),
          panel.background = element_rect(fill = "#f5f5f2", color = NA),
          legend.background = element_rect(fill = "#f5f5f2", color = NA),
          panel.border = element_blank(),
          ...
        )
      }
  
      crs &lt;- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +datum=WGS84 +units=m +no_defs"
      ctrys50m &lt;- ne_countries(scale = 50, type = "countries", returnclass = "sf") %&gt;%
         select(iso_a3, iso_n3, admin)
  
      ggplot() + 
        geom_sf(data = ctrys50m, alpha = 0.15, fill="grey") +
        coord_map() +
        coord_sf(crs = crs) +
        theme_map()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uSxvy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uSxvy.png" alt="enter image description here"></a></p>
  
  <p>In order to be able to nicely plot Earth contour, in <code>D3.js</code> a special GeoJSON <code>type</code>, <code>{type: "Sphere"}</code> has been added, see <a href="https://gis.stackexchange.com/a/44815/76173">this thread</a> which can be seen in action <a href="https://bl.ocks.org/mbostock/3757101" rel="noreferrer">here</a>: it is the exterior whole Earth black border in the following snapshot:</p>
  
  <p><a href="https://i.stack.imgur.com/LloKb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LloKb.png" alt="enter image description here"></a></p>
  
  <p>The only <em>trick</em> I found in <code>R</code>/<code>ggplot2</code> is the one published by Matt Strimas-Mackey, in his blog entry <a href="http://strimas.com/spatial/long-flights/" rel="noreferrer">Mapping the Longest Commericial Flights in R</a>, see the <a href="http://strimas.com/spatial/long-flights/#bounding-box-and-graticules" rel="noreferrer">Bounding box and graticules</a> section and the <code>make_bbox</code> and <code>project_recenter</code> functions.</p>
  
  <p>These are quite a lot of code and I was wondering whether some
  <code>sf</code> or <code>geom_sf</code> code would make to a cleaner/simpler code, so I tried:</p>
  
  <pre><code>    # whole world WSG84 bounding box
      sphere &lt;- ne_download(category = "physical", type = "wgs84_bounding_box", returnclass = "sf")
      sphere_laea &lt;- st_transform(sphere, crs)
      ggplot() + 
        geom_sf(data = sphere, fill = "#D8F4FF") +
        coord_sf(crs = crs) +
        geom_sf(data = ctrys50m, alpha = 0.15, fill="grey") +
        coord_map() +
        coord_sf(crs = crs) +
        theme_map()
  </code></pre>
  
  <p>What I get is just an extra "anti-meridian" (note the line from North pole...) and no <em>oceans</em> filled with <code>#D8F4FF</code>...
  And the polygon is quite irregular at the bottom (the D3.js gurus did some smart <a href="https://bl.ocks.org/mbostock/3795544" rel="noreferrer">adaptive resampling</a> to increase the accuracy of projected lines...)</p>
  
  <p><a href="https://i.stack.imgur.com/u9ZAo.png" rel="noreferrer"><img src="https://i.stack.imgur.com/u9ZAo.png" alt="enter image description here"></a></p>
  
  <p>Any ideas about what's wrong in my attempt to get a whole world polygon for ggplot2 world maps?
  (Thanks for reading this far!)</p>