Created
December 1, 2022 10:15
-
-
Save dakvid/d5f5f1ec48fca9769c37f46014f52b86 to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2022 | Day 26 | Islands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plonk the largest islands together on the page | |
# I was going to both make these to scale, and animate between them, but | |
# didn't have enough time up my sleeve. | |
library(glue) | |
library(dplyr) | |
library(sf) | |
library(rnaturalearth) | |
library(ggplot2) | |
library(patchwork) | |
world <- | |
ne_countries(scale = "large", type = "map_units", returnclass = "sf") | |
CRS_00 <- "+proj=ortho +lon_0=0 +lat_0=0" | |
COL_LAND <- "light green" | |
COL_BG <- "light blue" | |
COL_TEXT <- "black" | |
MAP_FONT <- "BellTopo Sans" | |
project_and_play <- | |
function(island_geo) { | |
merc_centroid <- | |
island_geo |> | |
st_centroid() | |
merc_coords <- | |
merc_centroid |> | |
st_coordinates() | |
projection <- | |
glue("+proj=ortho +lon_0={merc_coords[1, 'X']} +lat_0={merc_coords[1, 'Y']}") | |
projected_island <- | |
island_geo |> | |
st_transform(crs = projection) | |
projected_centroid <- | |
projected_island |> | |
st_centroid() | |
list( | |
island = projected_island, | |
centroid = projected_centroid, | |
projection = projection | |
) | |
} | |
map_island <- | |
function(island_list) { | |
ggplot() + | |
geom_sf(data = island_list$island, | |
fill = COL_LAND, colour = NA) + | |
geom_sf_text(data = island_list$centroid, | |
aes(label = island), | |
family = MAP_FONT, | |
size = 12, | |
colour = COL_TEXT) + | |
theme_void() + | |
theme(plot.background = element_rect(fill = COL_BG, colour = COL_BG)) | |
} | |
# Greenland ---- | |
greenland <- | |
world |> | |
filter(admin == "Greenland") |> | |
select(island = admin) |> | |
st_cast("POLYGON") |> | |
slice(1) |> | |
project_and_play() | |
gg_greenland <- | |
greenland |> map_island() | |
# New Guinea ---- | |
new_guinea <- | |
bind_rows( | |
world |> | |
filter(geounit == "Papua New Guinea") |> | |
transmute(island = "New Guinea") |> | |
st_cast("POLYGON") |> | |
slice(1), | |
world |> | |
filter(sovereignt == "Indonesia") |> | |
transmute(island = "New Guinea") |> | |
st_cast("POLYGON") |> | |
slice(4) | |
) |> | |
count(island) |> | |
select(-n) |> | |
project_and_play() | |
gg_new_guinea <- | |
new_guinea |> map_island() | |
# Borneo ---- | |
borneo <- | |
bind_rows( | |
world |> | |
filter(sovereignt == "Brunei") |> | |
transmute(island = "Borneo") |> | |
st_cast("POLYGON"), | |
world |> | |
filter(sovereignt == "Malaysia") |> | |
transmute(island = "Borneo") |> | |
st_cast("POLYGON") |> | |
slice(3), | |
world |> | |
filter(sovereignt == "Indonesia") |> | |
transmute(island = "Borneo") |> | |
st_cast("POLYGON") |> | |
slice(3) | |
) |> | |
count(island) |> | |
select(-n) |> | |
project_and_play() | |
gg_borneo <- | |
borneo |> map_island() | |
# Madagascar ---- | |
madagascar <- | |
world |> | |
filter(sovereignt == "Madagascar") |> | |
select(island = sovereignt) |> | |
st_cast("POLYGON") |> | |
slice(1) |> | |
project_and_play() | |
gg_madagascar <- | |
madagascar |> map_island() | |
# Baffin Island ---- | |
baffin <- | |
world |> | |
filter(sovereignt == "Canada") |> | |
transmute(island = "Baffin Island") |> | |
st_cast("POLYGON") |> | |
# mutate(order1 = row_number(), larea = st_area(geometry)) |> arrange(desc(larea)) | |
# 1, 125, 124, 2, 282, 17« | |
slice(125) |> | |
project_and_play() | |
gg_baffin <- | |
baffin |> map_island() | |
# Sumatra ---- | |
sumatra <- | |
world |> | |
filter(sovereignt == "Indonesia") |> | |
transmute(island = "Sumatra") |> | |
st_cast("POLYGON") |> | |
slice(59) |> | |
project_and_play() | |
gg_sumatra <- | |
sumatra |> map_island() | |
# Honshu ---- | |
honshu <- | |
world |> | |
filter(sovereignt == "Japan") |> | |
transmute(island = "Honshū") |> | |
st_cast("POLYGON") |> | |
slice(7) |> | |
project_and_play() | |
gg_honshu <- | |
honshu |> map_island() | |
# Victoria Island ---- | |
victoria <- | |
world |> | |
filter(sovereignt == "Canada") |> | |
transmute(island = "Victoria Island") |> | |
st_cast("POLYGON") |> | |
slice(124) |> | |
project_and_play() | |
gg_victoria <- | |
victoria |> map_island() | |
# Great Britain ---- | |
britain <- | |
bind_rows( | |
world |> | |
filter(geounit == "Wales") |> | |
transmute(island = "Great Britain") |> | |
st_cast("POLYGON") |> | |
slice(1), | |
world |> | |
filter(geounit == "Scotland") |> | |
transmute(island = "Great Britain") |> | |
st_cast("POLYGON") |> | |
slice(1), | |
world |> | |
filter(geounit == "England") |> | |
transmute(island = "Great Britain") |> | |
st_cast("POLYGON") |> | |
slice(1) | |
) |> | |
count(island) |> | |
select(-n) |> | |
project_and_play() | |
gg_britain <- | |
britain |> map_island() | |
# Ellesmere Island ---- | |
ellesmere <- | |
world |> | |
filter(sovereignt == "Canada") |> | |
transmute(island = "Ellesmere Island") |> | |
st_cast("POLYGON") |> | |
slice(282) |> | |
project_and_play() | |
gg_ellesmere <- | |
ellesmere |> map_island() | |
# Sulawesi ---- | |
sulawesi <- | |
world |> | |
filter(sovereignt == "Indonesia") |> | |
transmute(island = "Sulawesi") |> | |
st_cast("POLYGON") |> | |
slice(56) |> | |
project_and_play() | |
gg_sulawesi <- | |
sulawesi |> map_island() | |
# South Island ---- | |
south <- | |
world |> | |
filter(subunit == "New Zealand") |> | |
transmute(island = "Te Waipounamu") |> | |
st_cast("POLYGON") |> | |
slice(17) |> | |
project_and_play() | |
gg_south <- | |
south |> map_island() | |
gg_greenland + | |
(gg_new_guinea / gg_borneo / gg_madagascar) + | |
((gg_baffin + gg_sumatra + gg_honshu + gg_victoria) / | |
(gg_britain + gg_ellesmere + gg_sulawesi + gg_south)) + | |
plot_annotation(title = "The Twelve Largest Islands", | |
subtitle = "Approximately: 1 = (2 + 3 + 4) = (5 + 6 + 7 + 8 + 9 + 10 + 11 + 12)", | |
caption = "Note: islands not to scale", | |
theme = theme(plot.title = element_text(size = 96, family = MAP_FONT, colour = COL_TEXT, hjust = 0.5, margin = margin(c(20, 0, 10, 0))), | |
plot.subtitle = element_text(size = 48, family = MAP_FONT, colour = COL_TEXT, hjust = 0.5), | |
plot.caption = element_text(size = 32, family = MAP_FONT, colour = COL_TEXT, hjust = 0.95, margin = margin(c(60, 40, 0, 0))))) & | |
theme(plot.background = element_rect(fill = COL_BG, colour = COL_BG), | |
panel.background = element_rect(fill = COL_BG, colour = COL_BG)) | |
ggsave(path = "Day_26_Islands", filename = "day_26_islands.png", | |
width = 36, height = 26, dpi = 72) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment