# install.packages("grImport2")
# install.packages("ggflags",
# repos = c("https://jimjam-slam.r-universe.dev"))
library(ggflags)
library(rnaturalearth)
library(sf)
library(ggplot2)
library(glue)
library(ggspatial)
library(dplyr)
library(stringr)
world <- ne_countries() |>
st_transform("EPSG:8857")
world_points <- world |>
group_by(flag = str_to_lower(iso_a2_eh)) |>
st_cast("POLYGON") |>
mutate(surf = st_area(geometry)) |>
filter(flag != -99) |>
slice_max(surf, with_ties = FALSE) |>
ungroup()|>
select(flag, sovereignt) |>
st_point_on_surface()Day 21-22 of 30DayMapChallenge: « Icons » & « Natural Earth » (previously).
The world as flags…
Data
Map
world_points |>
bind_cols(st_coordinates(world_points)) |>
ggplot() +
geom_sf(data = world, color = "snow2", fill = "snow2") +
geom_flag(aes(X, Y, country = flag), size = 4) +
labs(title = "World Countries",
subtitle = "by flags",
caption = glue("data: Natural Earth - Flags: EmojiOne
{st_crs(world_points)$Name}
https://r.iresmi.net - {Sys.Date()}")) +
theme_void() +
theme(plot.caption = element_text(size = 7, color = "grey40"),
plot.margin = unit(c(.2, .2, .2, .2), units = "cm"))
