Flags | R bloggers

Flags | R bloggers

[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report a problem with 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.

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

Day 21-22 of 30 Day Card Challenge: « Icons » & « Natural Earth » (earlier).

The world as flags…

Facts

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

Card

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


#Flags #bloggers

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *