Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Created June 8, 2022 13:09
Show Gist options
  • Save charliejhadley/7eab29106771b2da5bff144d3a48ec46 to your computer and use it in GitHub Desktop.
Save charliejhadley/7eab29106771b2da5bff144d3a48ec46 to your computer and use it in GitHub Desktop.
stretchy-antarctica.R
library(tidyverse)
library(sf)
library(rnaturalearthdata)
countries110 %>%
st_as_sf() %>%
st_transform(crs = 3857) %>%
ggplot() +
geom_sf()
@Nowosad
Copy link

Nowosad commented Jun 8, 2022

Hacky improvement:

library(ggplot2)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.3, PROJ 8.2.1; sf_use_s2() is TRUE
library(rnaturalearth)
sf::sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off

countries110 %>%
  st_as_sf() %>% 
  st_crop(xmin = -180, ymin = -86, xmax = 180, ymax = 84) %>% 
  st_transform(crs = 3857) %>% 
  ggplot() +
  geom_sf()
#> although coordinates are longitude/latitude, st_intersection assumes that they are planar
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries

Created on 2022-06-08 by the reprex package (v2.0.1)

@charliejhadley
Copy link
Author

That's a more direct solution than what I was doing by cropping within coord_sf(), thanks!

 coord_sf(crs = 3857, expand = TRUE,
           ylim = c(-pi * 6378137, pi * 6378137))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment