Skip to content

Instantly share code, notes, and snippets.

@dakvid
Created November 28, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakvid/61bb631d18fd55214d9bd54f5f401201 to your computer and use it in GitHub Desktop.
Save dakvid/61bb631d18fd55214d9bd54f5f401201 to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2021 - Day 28 - The Earth is not flat
# Draw a world map with an AdamsII projection
# For #30DayMapChallenge 2021 - Day 28 - The Earth is not flat
# -- David Friggens, November 2021
library(sf)
library(dplyr)
library(ggplot2)
library(rnaturalearth)
library(ggtext)
adams2 <- "+proj=adams_ws2"
world_medium <-
ne_countries(scale = "medium", returnclass = "sf")
adams_world <-
world_medium %>%
st_transform(crs = adams2)
adams_bbox <-
adams_world %>%
st_bbox()
adams_diamond <-
list(
cbind(
c(-180, -180, 180, 180, 180, -180, -180),
c(0, 90, 90, 0, -89.9, -89.9, 0)
)
) %>%
st_polygon() %>%
st_sfc(crs = 4326L) %>%
st_transform(crs = adams2)
adams_bbox <- adams_diamond %>% st_bbox()
xn <- adams_bbox["xmin"]; xx <- adams_bbox["xmax"]; yn <- adams_bbox["ymin"]; yx <- adams_bbox["ymax"];
cx_lo <- (xx + -xn) * .25 + xn
cx_hi <- (xx + -xn) * .75 + xn
cy_lo <- (yx + -yn) * .19 + yn
cy_hi <- (yx + -yn) * .74 + yn
plot_labels <-
tribble(
~x, ~y, ~label_angle, ~label_size, ~label_text,
cx_lo, cy_hi, 45, 36, "The World is a Flat Square",
cx_hi, cy_hi, -45, 20, "#30DayMapChallenge 2021 - Day 28 - The Earth is not flat",
cx_lo, cy_lo, 135, 20, "Projection: Adams World in a Square II",
cx_hi, cy_lo, -135, 20, "Map by David Friggens @dakvid"
) %>%
st_as_sf(coords = c("x", "y"),
crs = adams2)
gg_adams <-
ggplot() +
geom_sf(data = adams_diamond,
fill = "dark blue") +
geom_sf(data = adams_world,
fill = "dark green", color = NA) +
geom_richtext(data = plot_labels,
stat = "sf_coordinates",
family = "High Alpine",
aes(geometry = geometry,
label = label_text,
angle = label_angle,
size = label_size),
vjust = 0,
fill = NA, label.colour = NA) +
scale_size_identity() +
theme_void() +
theme(plot.background = element_rect(fill = "white", colour = NA),
panel.background = element_rect(fill = "white", colour = NA),
legend.position = "none")
ggsave(plot = gg_adams,
"Day_28/Day_28_adams_square.png",
width = 24, height = 24, dpi = 72)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment