install.packages(c('gapminder','ggplot', 'ggplot2','gganimate','gifski'), repos = "http://cran.us.r-project.org")
## Warning: package 'ggplot' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## package 'gapminder' successfully unpacked and MD5 sums checked
## package 'ggplot2' successfully unpacked and MD5 sums checked
## package 'gganimate' successfully unpacked and MD5 sums checked
## package 'gifski' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'gifski'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem
## copying F:\R\R-4.1.2\library\00LOCK\gifski\libs\x64\gifski.dll to F:
## \R\R-4.1.2\library\gifski\libs\x64\gifski.dll: Permission denied
## Warning: restored 'gifski'
##
## The downloaded binary packages are in
## C:\Users\DELL\AppData\Local\Temp\RtmpKQPhu0\downloaded_packages
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.3
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.1.3
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.1.3
View(gapminder)
This is the animated plot code for showing the scatterplot of Continent wise life expectancy.
p1 <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
# Animating the plot
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'Life expectancy') +
transition_time(year) +
ease_aes('linear')
animate(p1)
The below code is used to save the animated plot as a GIF.
anim_save('plot_gdpPercap_lifeExp.gif', width=1600, height=400)