plt <-
df_plt |>
ggplot(aes(x = reorder(rank, gdp), y = gdp)) +
geom_col(fill = "steelblue", alpha = 0.6) +
geom_image(aes(image = cflags, y = -2.3), size = 0.13, by = "width") +
scale_y_continuous(labels = function(y) ifelse(y == 0, paste0(y), paste0(y, "k"))) +
geom_text(aes(label = gdp), hjust = -0.1, color = "darkgrey", fontface = "bold") +
geom_label(aes(label = paste("Year:",year)), x = 2, y = 30, size = 8, fill = "white", col = "gray") +
labs(
x = NULL, y = "GDP, PPP in Mlrd. in USD (k = 1000)",
title = "**Top ten countries by GDP, PPP in 1990-2024**",
caption = social_caption) +
coord_flip() +
theme_minimal() +
theme(
plot.title = element_markdown(size=14, color="steelblue4", hjust = 0.5),
plot.caption = ggtext::element_markdown(size=14, hjust = 0.5),
plot.background = element_rect(fill = "ghostwhite"),
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")
)
plt_anim <-
plt +
transition_states(year, wrap = FALSE, transition_length = 1, state_length = 1) +
enter_fade() +
exit_fade()
anim <- animate(
plt_anim,
duration = 45,
start_pause =5,
end_pause = 5,
renderer = gifski_renderer()
)
anim