1

I'm still learning how to use R. I'm trying to display points in North America and Eastern Russia using the package "rnaturalearth". I'd like to just show Russia and North America, rather than all of Europe. I've included a picture with the area of the world that I want in a box here. I get this error whenever I input positive and negative longitude values.

Error in st_normalize.sfc(x, c(x_range[1], y_range[1], x_range[2], y_range[2])) : 
  domain must have a positive range

I couldn't find anything online, although I'm sure it's probably pretty simple. Any help would be appreciated!

Here is the code for the general mapping:

world <- ne_countries(scale = "medium", returnclass = "sf")

ggplot(data = world)+
  geom_sf()+
coord_sf(xlim = c(160, -60), ylim = c(20, 90), expand = FALSE)
Dave2e
  • 22,192
  • 18
  • 42
  • 50

1 Answers1

1

I had almost the exact same challenge to try and solve and found your question while trying to figure it out. Here are the links which helped me get the output I wanted. I won't give an exact solution myself as I think these links already have the solution well laid out.

This question contains almost the exact process you are looking for:

https://gis.stackexchange.com/questions/332106/union-anti-meridian-multipolygons-after-re-centering-world-map

This is what the individual in the above question used as a reference to edit the code from (which also includes the packages needed to do this):

https://github.com/valentinitnelav/valentinitnelav.github.io/blob/master/gallery/Shift%20central%20(prime)%20meridian.R#L73

Once you have the polygons shifted you can use "coord_sf()" as you tried before to get the subset of the map you want.

The only issue I have with this specific solution is that it will shift the longitude values on the map. This means they do not accurately represent the actual longitude values. So make sure to take that into account if you want to show the longitude values on the map.

I hope this helps you get the map you want!

Edit: I just remembered this site has a different way to get a similar solution under "Example of a failed transformation", depending on the map projection you want. https://mgimond.github.io/Spatial/coordinate-systems-in-r.html