Tidyuesday

#Bibliotecas necesarias
library(tidytuesdayR)
library(tidyverse)
library(lubridate)
library(stringr)
library(forcats)
library(ggthemes)
library(ggsci)
library(gganimate)
#Lectura de Datos
tt <- tt_load(2019,47) 
tt_dat <- tt$nz_bird 
save(df,file = "nz_bird.Rdata")

#Seleccion Top 15

data_top10 <-   tt_dat %>% 
  filter(vote_rank == "vote_1") %>% 
  group_by(bird_breed) %>% 
  summarise(n=n()) %>% 
  top_n(10)
top10 <- c(data_top10$bird_breed)
#Seleccion de datos
df <- tt_dat  %>%  
  mutate(date = ymd_hms(str_c(as.character(date)," ",as.character(hour),":00:00")),
         bird_breed = fct_explicit_na(bird_breed) ) %>% 
  select(-hour) %>% 
  group_by(vote_rank,bird_breed,date) %>% 
  summarise(Count = n()) %>% 
  filter(bird_breed %in% as.factor(top10))
g <- 
  ggplot(df,aes(x=fct_rev(fct_infreq(bird_breed)), y =Count , fill = bird_breed))+
  stat_summary(fun.y = "sum", geom = "point",size=4.5, shape ="\U1F426") +
  coord_flip() +
  facet_wrap(~vote_rank,scales = "free") +
  theme_hc()+
  scale_fill_igv()+
  theme(legend.position = "none",
        plot.caption = element_text(size = 11,color = "grey76", hjust = .98),
        plot.title = element_text(hjust = 0.5, size=20, color="grey76"),
        plot.subtitle  = element_text(hjust = 0.5, size=13, color="grey76"),
        panel.background = element_rect(fill="grey10"),
        strip.background = element_rect(fil="grey7"),
        plot.background = element_rect(fill="grey7"),
        axis.text = element_text(family = "Roboto Mono",
                                   size = 10,
                                   colour = "grey76"),
        strip.text.x =element_text(family = "Roboto Mono",
                                   size = 12,
                                   colour = "grey76"),
        axis.title =  element_text(family = "Roboto Mono",
                                   size = 16,
                                   colour = "white"),
        line = element_line(linetype = "dashed"),
        #axis.line = element_line(arrow = arrow(), color="grey50"),
        panel.spacing = unit(2.5, "lines"))+
  labs(title = "Top 10 for the new zealand bird of year",
       subtitle = "Day: {frame_time}",
       y="Number of Votes",
       x="Birds",
       fill="Language",
       caption = "Vizualization by Duvan Nieves | Data : 'NZ Bird of the Year'  by New Zealand Forest and Bird Org")+
  transition_components(date)+
  enter_fade() +
  exit_fade()

animate(g, renderer = gifski_renderer(),height = 600, width =800,fps = 2)