pl24 <-
# data -----------------------------------------------
df |>
filter(
year==2024
) |>
mutate(
images = case_when(
ccode == "ARM" ~ paste0(imgpat, "AM.png"),
ccode == "AZE" ~ paste0(imgpat, "AZ.png"),
ccode == "BLR" ~ paste0(imgpat, "BY.png"),
ccode == "KAZ" ~ paste0(imgpat, "KZ.png"),
ccode == "KGZ" ~ paste0(imgpat, "KG.png"),
ccode == "RUS" ~ paste0(imgpat, "RU.png"),
ccode == "TJK" ~ paste0(imgpat, "TJ.png"),
ccode == "TKM" ~ paste0(imgpat, "TM.png"),
ccode == "UZB" ~ paste0(imgpat, "UZ.png"),
TRUE ~ ccode)
) |>
# plot aes ----------------------------------------------------
ggplot(aes(
xmin = 0,
xmax = pop,
y = rank,
ymin = rank - 0.45,
ymax = rank + 0.45,
fill = ccode)) +
geom_rect(alpha = 0.5) +
# axises, labels
scale_x_continuous(
limits = c(0,150),
breaks = seq(0, 150, 25),
labels = function(x) paste0(x, "M"),
expand = expansion(c(0.09, 0.0))) +
geom_image(aes(y= rank, image = images),
x = -10, size = 0.07, by="height") +
geom_label(aes(x = pop, label = as.character(pop)),
colour = "white", hjust=0.0) +
geom_label(aes(label = paste("Year:",year)),
x = 125, y = 2, size = 8, fill = "white", col = "gray") +
# title, caption ---------------------------------------------
labs(
x = "Population (in millions)",
y = NULL,
title = "Population in CIS countries in 2024",
caption = social_caption) +
# format, theme ----------------------------------------------
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(size=14, face = "bold", color="steelblue4", hjust = 0.5 ),
plot.caption = ggtext::element_markdown(size=12, hjust = 0.5),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
axis.line.x = element_line(colour = "gray"),
axis.text.y = element_blank())
# show plot
pl24