animation in R
////////////////////////////

Using R for animation offers several advantages, including robust data
  visualization capabilities through packages like gganimate, which 
  seamlessly integrates with ggplot2. This allows for the creation 
  of dynamic, informative, and visually appealing animations directly
  from data analysis workflows. 

Additionally, R's extensive library ecosystem supports a wide range 
   of customization and output options, making it easy to tailor 
   animations for specific needs, whether for research, presentations,
   or educational purposes. The ability to create reproducible and 
   programmatically generated animations ensures consistency and 
   accuracy in representing complex data over time.

////////////////////////////

One example
////////////////////////////

library(gapminder)
library(ggplot2)
library(gganimate)
 	# Make a ggplot, but add frame=year: one image per year
ggplot(gapminder,aes(gdpPercap,lifeExp,size=pop,color=continent)) +
geom_point() +  scale_x_log10() +  theme_bw() +  
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') + transition_time(year)+ease_aes('linear')
anim_save("abc.gif")  # Save at gif:

////////////////////////////

animation: stock return comparison
////////////////////////////

library(ggplot2)
library(tidyverse)
library(gganimate)
library(directlabels)
library(png)
library(transformr)
library(grid)
# Read Data
df0 = read.table(text = 
  " Year ret_A ret_B
    1984 0.79     0.1
    1989 0.38     0      
    1991 0.45     0.17
    1996 0.27     0.23
    1998 0.27    0.31
    1999 0.22    0.35
    2004 0.28    0.27
    2009 0.4     0.23
    2014 0.09    0.52
    2019 0.07    0.56
  ", header=TRUE)

names<-sub("ret_","", colnames(df0))
a<-data.frame(df0[,c(1,2)],names[2])
b<-data.frame(df0[,c(1,3)],names[3])
colnames(a)<-c("Year","ret","stock")
colnames(b)<-c("Year","ret","stock")
df<-rbind(a,b)

t<-'Comparison between stocks A and B'
# Set Theme
theme_set(theme_minimal())
# Plot and animate
title<-"Comparison between returns of stocks A and B"
p =  
  ggplot(data = df, aes(x= factor(Year), y=ret, group=stock, colour=stock)) +
  geom_line(size=2, show.legend = FALSE) +
  scale_color_manual(values=c("#ff9933", "#006400")) +
  scale_x_discrete(position = "top") +
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  labs(title =title, x = NULL, y = NULL) +
  geom_text(aes(label=scales::percent(ret, accuracy = 1),vjust= -2), show.legend = FALSE) +
  theme(plot.title = element_text(hjust = 0.5)) +
  geom_dl(aes(label=stock), method="last.points") +
  transition_reveal(Year) +  coord_cartesian(clip = 'off') + 
  ease_aes('cubic-in-out')

animate(p, fps = 5, duration = 20, width = 800, height = 400)
anim_save("my.gif", p)

////////////////////////////