ggplot2 – Animated R graph

I try to generate animated plot about annual average precipitation of five different countries based on yearly rainfall data.

I use plotting package “gganimated” and “ggplot2” but I did not satisfy. I would like to create graphs like at 00:45 below video

www.youtube.com/watch?v=adelgqOlZwE&t=18s

How I edit my code to create graph like this? Thanks in advance.

Note: Resource file can be downloaded at belowlink

easyupload.io/ud5u5m

 install.packages("gganimate")
library(gganimate)
install.packages("gifsski")
install.packages("av")
install.packages("dplyr")
install.packages("rio")
library(dplyr)

data <- rio::import ("/Users/VATAN/Desktop/a/data.xlsx")

str(data)

# Plot and animate
p =  
  ggplot(data, aes(x= factor(Year), y=precipatation, group=Party, colour=Party)) +
  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="Lok Sabha Election : % of seats won", 
        x = NULL, y = NULL) +
  geom_text(aes(label=scales::percent(Perc_Seats, accuracy = 1),
                vjust= -2), show.legend = FALSE) +
  theme(plot.title = element_text(hjust = 0.5)) +
  geom_dl(aes(label=Party), method="last.points") +
  transition_reveal(Year) +
  coord_cartesian(clip = 'off') + 
  ease_aes('cubic-in-out')

animate(p, fps = 10, width = 800, height = 400)
anim_save("election.gif")


Read more here: Source link