South Up Equal Earth Projection in R


Yup - I'm still banging on about this! This time, in R

Result

Map of the world, south up, NZ in the centre, with labels and colours.

The colours are wrong, and the labels need adjustment - but not bad for a few lines of code!

Code

 Rlibrary(tidyverse)
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)

centre <- 160 # NZ mostly centred, prevents Africa and South America wrapping.
projection <- "eqearth" # Other good projections are wag1 wag7 eck4 eqearth

crs_string <- paste( "+proj=", projection, " +lon_0=", centre, " +axis=wsu", sep="") # WSU puts South up

target_crs <- st_crs(  crs_string  )

worldrn <- ne_countries( scale = "medium", returnclass = "sf" ) %>%
   st_make_valid()

offset <- 180 - centre

#  Recalculate the polygons
polygon <- st_polygon( x = list(rbind(
                                 c(-0.0001 - offset, 90),
                                 c(0 - offset, 90),
                                 c(0 - offset, -90),
                                 c(-0.0001 - offset, -90),
                                 c(-0.0001 - offset, 90)
))) %>%
   st_sfc() %>%
   st_set_crs(4326)


# modify world dataset to remove overlapping portions with world's polygons
world2 <- worldrn %>% st_difference(polygon)

# Transform
world3 <- world2 %>% st_transform(crs = target_crs)
ggplot(data = world3, aes(group = admin)) +
   #geom_sf( fill = "red" ) +
   geom_sf( fill = world3$mapcolor13, lwd = 0 ) + # remove borders
   geom_sf_label( aes( label = name_long ), label.size = 0, fill = NA, size = 1 ) +
   theme( panel.grid.major = element_line( color = gray(.5), linetype = "dashed", size = 0.5 ),
      panel.background = element_rect( fill = "#A7C7E7"))

#  Uncomment to save the map
#ggsave("map.png", width = 32, height = 18, units = "cm")

Further Reading


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

2 thoughts on “South Up Equal Earth Projection in R”

What links here from around this blog?

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">