Veremos la creación de animaciones usando la librerĆa gganimate.
gganimate es una extensión de ggplot2 para la creación de grÔficos animados a partir de un grÔfico de ggplot. Este paquete nos proporciona nuevas funciones que nos permiten personalizar el cambio en el tiempo.
Las instrucciones mas relevantes son:
library(gapminder)
library(gganimate)
library(gifski)
library(tidyverse)
?gapminder
head(gapminder)
## # A tibble: 6 x 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
ggplot(gapminder,aes(x = gdpPercap, y=lifeExp, size = pop, colour = country))+
geom_point(show.legend = FALSE, alpha = 0.7)
p<-ggplot(gapminder,aes(x = gdpPercap, y=lifeExp, size = pop, colour = country))+
geom_point(show.legend = FALSE, alpha = 0.7)
p
p<- p +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
p
?transition_time
p + transition_time(year) +
labs(title = "Year: {frame_time}")
p + transition_time(year) +
labs(title = "Year: {frame_time}") +
facet_wrap(~continent)
p + transition_time(year) +
labs(title = "Year: {frame_time}") +
shadow_wake(wake_length = 0.1, alpha = FALSE)
p + transition_time(year) +
labs(title = "Year: {frame_time}") +
shadow_mark(alpha = 0.3, size = 0.5)