Code
library(sf)
library(tmap)
library(dplyr)
library(stringr)
library(ggplot2)
source("~/Documents/code/30-day-maps-2023/maps/utils.R")↑
I have nothing to add to this one.
library(sf)
library(tmap)
library(dplyr)
library(stringr)
library(ggplot2)
source("~/Documents/code/30-day-maps-2023/maps/utils.R")focus <- "Antarctica"
lon0 <- 0
lat0 <- -90
proj <- str_glue("+proj=ortho lon_0={lon0} lat_0={lat0}")world <- st_read("data/ne_110m_admin_0_map_units.gpkg") %>%
st_make_valid() %>%
select(CONTINENT) %>%
st_transform(proj) %>%
st_make_valid() %>%
filter(!st_is_empty(.)) %>%
group_by(CONTINENT) %>%
summarise()
continent <- world %>%
filter(CONTINENT == focus)
graticule <- get_graticule(spacing = 15)tmapggplot2We need ggspatial for a north arrow here.
But even then, to customize it I have to make my own function.
up_arrow <- function(label = "UP") {
text_label = label
text_adj = c(0.5, 0.5)
grid::gList(
grid::polygonGrob(
x = c(0.625, 0.5, 0.5),
y = c(0.3, 0.85, 0.4),
default.units = "npc",
gp = grid::gpar(
lwd = 1,
col = "black",
fill = "black"
)
),
grid::polygonGrob(
x = c(0.375, 0.5, 0.5),
y = c(0.3, 0.85, 0.4),
default.units = "npc",
gp = grid::gpar(
lwd = 0.5,
col = "black",
fill = NULL
)
),
grid::textGrob(
label = text_label,
x = 0.5,
y = 1,
hjust = 0.5,
vjust = 0.5,
rot = 0,
gp = grid::gpar(fontsize = 9)
)
)
}On the other hand, since I’ve done the work, I might as well make the most of it.
library(ggspatial)
ggplot(world) +
geom_sf(linewidth = 0) +
geom_sf(data = graticule, col = "lightgrey", linewidth = 0.25) +
annotation_north_arrow(location = "br", style = up_arrow) +
annotation_north_arrow(location = "tr", style = up_arrow("LEFT"), rotation = 90) +
annotation_north_arrow(location = "tl", style = up_arrow("DOWN"), rotation = 180) +
annotation_north_arrow(location = "bl", style = up_arrow("RIGHT"), rotation = 270) +
theme_void()