1

Consider the map of Europe below. Parts of Russia are on the other side of the map. How might I "recenter" the map so that there is less empty space? I guess I need to somehow move the polygons on the left to the right?

library(rnaturalearth)
library(tidyverse)

ne_countries(returnclass = "sf", continent = "europe") %>% 
  ggplot() + 
  geom_sf()

enter image description here

Thank you very much!

Created on 2022-07-02 by the reprex package (v2.0.1)

Kene David Nwosu
  • 828
  • 6
  • 12
  • Something similar is described here, though I can't replicate their results yet: https://datascience.blog.wzb.eu/2019/04/30/zooming-in-on-maps-with-sf-and-ggplot2/ – Caspar V. Jul 03 '22 at 18:20

1 Answers1

1

you can give it a new coordinate system to transform it to where your area of interest is centered on your map using the coord_sf() function.

for my example I grabbed a somewhat arbitrary coordinate system defined as well known text (WKT) from: https://projectionwizard.org/

library(rnaturalearth)
library(tidyverse)


domainCRS<- paste('PROJCS["ProjWiz_Custom_Lambert_Azimuthal"',
            'GEOGCS["GCS_WGS_1984"',
        'DATUM["D_WGS_1984"',
        'SPHEROID["WGS_1984",6378137.0,298.257223563]]',
        'PRIMEM["Greenwich",0.0]',
        'UNIT["Degree",0.0174532925199433]]',
        'PROJECTION["Lambert_Azimuthal_Equal_Area"]',
        'PARAMETER["False_Easting",0.0]',
        'PARAMETER["False_Northing",0.0]',
        'PARAMETER["Central_Meridian",109.69]',
        'PARAMETER["Latitude_Of_Origin",12.55]',
        'UNIT["Meter",1.0]]',
        sep = ',')

map<-ne_countries(returnclass = "sf", continent = "europe")
  ggplot() + 
  geom_sf(data = map)+
  coord_sf(crs = domainCRS)
geetlord
  • 33
  • 1
  • 5
  • Thank you so much. There still seems to be an annoying polygon on the left though. I guess there is trivial way to move it to the right? – Kene David Nwosu Aug 05 '22 at 14:31
  • That eastern polygon shows up in your original map. It is a territory of France. If you limit your plot to `geom_sf(data = map[map$sovereignt == "France",])` you will see that it appears in that map. – geetlord Aug 05 '22 at 19:08
  • Try this for a more conventional rectangular projection: 'domainCRS<- paste('PROJCS["ProjWiz_Custom_Plate_Carree"', 'GEOGCS["GCS_WGS_1984"', 'DATUM["D_WGS_1984"', ' SPHEROID["WGS_1984",6378137.0,298.257223563]]', ' PRIMEM["Greenwich",0.0]', ' UNIT["Degree",0.0174532925199433]]', 'PROJECTION["Plate_Carree"]', 'PARAMETER["False_Easting",0.0]', 'PARAMETER["False_Northing",0.0]', 'PARAMETER["Central_Meridian",105]', 'UNIT["Meter",1.0]]', sep = ",")' – geetlord Aug 05 '22 at 19:16