Reordering bars in GGanimate visualization

Dynamic ggplots with GGanimate! In this post we code evolution of a barplot over time and reordering its bar. ¡Click on and discover it!

R gganimate and ggplot2 plot where the bars are reordering in time and also entering and leaving the screen remaining the top 4 countries.

Last week several gganimate visualizations came to my feed. Some R users were wondering about reordering gganimate and ggplot2 bars as long as them are evolving (over animation time).

Then, we came up with this R viz where several bars are not only evolving and reordering over time but leaving and joining the chart. We want the top 4 countries over time, then the remaining countries in each timestamp should leave.

You can achieve this effect and this kind of gganimate visualization following this commented code:


Tune up your R visualizations on TypeThePipe


Carlos Vecina
Carlos Vecina
Data Scientist & TechLead at Bankinter

Data Scientist & TechLead at Bankinter | AI & Data Science for Business