South Up Equal Earth Projection in R

by @edent | | 2 comments

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

library(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

2 thoughts on “South Up Equal Earth Projection in R

  1. my favourite is the aboriginal conception/orientation of australia in the centre of the map 🥰

  2. 🌎🌍🌏 < now we just need a new emoji!

Leave a Reply

Your email address will not be published. Required fields are marked *