Skip to content

Instantly share code, notes, and snippets.

@dakvid
Created November 14, 2022 10:42
Show Gist options
  • Save dakvid/9bbdfb8d22e3555b47b25e1b2b999403 to your computer and use it in GitHub Desktop.
Save dakvid/9bbdfb8d22e3555b47b25e1b2b999403 to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2022 - Day 14 - Hexagon
# For #30DayMapChallenge 2022 Day 14 Hexagon
# Make an Eckert II projected world map, copying the idea from
# https://twitter.com/abiyugiday/status/1592065754903744513
library(sp)
library(sf)
library(rnaturalearth)
library(maptools)
library(ggplot2)
library(ragg)
ECK <- "+proj=eck2 +lon_0=160"
land <-
ne_countries(scale = "medium", returnclass = "sp") |>
nowrapSpatialPolygons(offset = -20) |>
st_as_sf()
sea <-
land |>
st_bbox() |>
st_make_grid(n = 50) |>
st_as_sf()
LAND_COLOUR <- "dark green"
SEA_COLOUR <- "dark blue"
BG_COLOUR <- "#111111"
TEXT_COLOUR <- "#fefefe"
agg_png(filename = "eckert2.png",
width = 1200, height = 660,
background = BG_COLOUR)
ggplot() +
geom_sf(data = sea, fill = SEA_COLOUR, colour = SEA_COLOUR) +
geom_sf(data = land, fill = LAND_COLOUR, colour = LAND_COLOUR) +
coord_sf(crs = ECK) +
theme_void() +
labs(title = "Eckert II Projection") +
theme(panel.background = element_rect(fill = BG_COLOUR, colour = BG_COLOUR),
plot.background = element_rect(fill = BG_COLOUR, colour = BG_COLOUR),
plot.title = element_text(family = "Times", size = 30, colour = TEXT_COLOUR, hjust = 0.5))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment