|
Autor: Email: RPubs: Twitter: Linkedin: |
Jack Bedoya Acosta |
|
|
library(gganimate)
library(ggplot2)
library(dplyr)
library(janitor)
library(readxl)
library(readxl)
head(datos)
## # A tibble: 6 x 3
## Temporada equipo cam
## <dbl> <chr> <dbl>
## 1 1957  Emelec 1
## 2 1960  Emelec 1
## 3 1960  Barcelona 1
## 4 1961  Emelec 2
## 5 1961  Barcelona 1
## 6 1962  Everest 1
datos2 <- datos %>%
group_by(Temporada) %>%
arrange(Temporada, desc(cam)) %>%
mutate(ranking = row_number()) %>%
filter(ranking <=9)
staticplot = ggplot(datos2 , aes(ranking, group = equipo)) +
geom_tile(aes(y = cam/2,
height = cam,
width = 0.9), alpha = 0.9, color = NA) +
scale_fill_manual()+
geom_text(aes(y = 0, label = paste(equipo, " ")), vjust = 0.1, hjust = 1,size=6) +
geom_text(aes(y=cam,label = cam, hjust=-1,size=18,face="bold")) +
coord_flip(clip = "off", expand = FALSE) +
scale_y_continuous(labels = scales::comma) +
scale_x_reverse() +
guides(color = FALSE, fill = FALSE) +
theme(
axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position="none",
panel.background=element_rect(fill = "gray97"),
panel.border=element_blank(),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
plot.title=element_text(size=26, hjust=0.5, face="bold", colour="black"),
plot.subtitle=element_text(size=18, hjust=0.5, face="bold", color="gray29"),
plot.caption =element_text(size=18, hjust=1, face="italic", color="darkslategrey"),
plot.background=element_rect(fill = "gray96"),
plot.margin = margin(2,2, 2, 5, "cm"))
anim = staticplot + transition_states(Temporada, transition_length = 4, state_length = 1) +
view_follow(fixed_x = TRUE) +
labs(title = 'Campeonatos en Ecuador',
subtitle = 'Acumulados al Año : {closest_state} ',
caption = "Author: Jack Bedoya")
animate(anim, 200, fps = 25, width = 1200, height = 1000,duration = 28,
renderer = gifski_renderer("gganim.gif"))