Skip to content

Instantly share code, notes, and snippets.

@sicarul
Created April 11, 2019 03:00
Show Gist options
  • Save sicarul/f4054ba71c7b2a15a697e1b5b010859a to your computer and use it in GitHub Desktop.
Save sicarul/f4054ba71c7b2a15a697e1b5b010859a to your computer and use it in GitHub Desktop.
Distribucion de goles por torneo
library(tidyverse)
library(gganimate)
library(ggimage)
partidos <- readr::read_delim("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-04-10/partidos.txt",delim = "\t")
# unique(partidos$anfitrion)
mapping_paises = tribble(
~codigo, ~anfitrion,
"IT","Italia",
"UY","Uruguay",
"FR","Francia",
"BR","Brasil",
"CH","Suiza",
"SE","Suecia",
"CL","Chile",
"GB","Inglaterra",
"MX","Mexico",
"DE","Alemania occidental",
"AR","Argentina",
"ES","España",
"US","Estados Unidos",
"KR","Corea del sur y Japón",
"DE","Alemania",
"ZA","Sudáfrica",
"RU","Rusia"
)
goles_partidos = partidos %>%
mutate(goles=equipo_1_final + equipo_2_final,
decada=floor(anio/10)*10) %>%
inner_join(mapping_paises, by='anfitrion')
p = ggplot(goles_partidos, aes(x=goles)) +
geom_density(fill='#eeeeff') +
geom_flag(aes(x=11, y=0.25, image=codigo), size=0.2) +
theme_minimal() +
ggtitle('Distribucion de goles por torneo - Año {closest_state}') +
transition_states(anio, transition_length = 3, state_length = 2) +
ease_aes('sine-in-out')
a = animate(p, nframes=600, fps=30)
anim_save('torneos.gif', animation=a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment