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")
<- "Antarctica"
focus <- 0
lon0 <- -90
lat0 <- str_glue("+proj=ortho lon_0={lon0} lat_0={lat0}") proj
<- st_read("data/ne_110m_admin_0_map_units.gpkg") %>%
world st_make_valid() %>%
select(CONTINENT) %>%
st_transform(proj) %>%
st_make_valid() %>%
filter(!st_is_empty(.)) %>%
group_by(CONTINENT) %>%
summarise()
<- world %>%
continent filter(CONTINENT == focus)
<- get_graticule(spacing = 15) graticule
tmap
tm_shape(world) +
tm_fill() +
tm_shape(graticule) +
tm_lines(col = "lightgrey", lwd = 0.5) +
tm_compass(cardinal.directions = c("UP", "S", "E", "W")) +
tm_layout(frame = FALSE)
ggplot2
We need ggspatial
for a north arrow here.
But even then, to customize it I have to make my own function.
<- function(label = "UP") {
up_arrow = label
text_label = c(0.5, 0.5)
text_adj
::gList(
grid::polygonGrob(
gridx = 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"
)
),::polygonGrob(
gridx = 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
)
),::textGrob(
gridlabel = 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()