Flags

R-bloggers 2025-11-24

[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A photo of world flags

Colors of Youth !! – CC BY-NC-ND by Rahul Sheel

Day 21-22 of 30DayMapChallenge: « Icons » & « Natural Earth » (previously).

The world as flags…

Data

# 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()

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"))
Map of countries located by their flags
Figure 1: Flags of the world
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Continue reading: Flags