library(tidyverse)
library(Lahman)
library(gganimate)
library(ggthemes)
library(ggimage)
Teams00_19 <- Teams %>% filter(lgID == "NL" & divID == "C" & yearID >=2000 & yearID <=2019)
NLC.Team.Logo <- read.csv("Team Logo.csv")
Teams2000.NLC <- inner_join(Teams00_19, NLC.Team.Logo, by="teamID")
p2 <- ggplot(Teams2000.NLC, aes(R, W)) +
geom_image(aes(image = logo), size = 0.08)+
ggtitle("Distribution of Runs Scored and Win in 2019 Season")+
theme_classic()+
theme(plot.title = element_text(color="#C3142D", size=12, face="bold"))+
labs(title = 'Season: {frame_time}', x = "Runs Scored", y = "W") +
transition_time(yearID) +
ease_aes()
animate(p2,
duration = 30,
fps = 10)

# anim_save("SLM418/NLC Wins and Runs Scored 2000-2019.gif")
p3 <- ggplot(Teams2000.NLC, aes(yearID, W, color=teamID)) +
geom_line()+
labs(title = "Team Performance in NLC 2000-2019", x = "Seasons", y = "Wins")+
scale_color_discrete(name = "") +
scale_color_manual(values = c("#ea5545", "#ef9b20", "#87bc45", "#27aeef", "#00bfa0")) +
theme_economist() +
theme(axis.title.x = element_text(margin = margin(t = 10)),
axis.title.y = element_text(margin = margin(r = 10)),
legend.text = element_text(size=10),
legend.position = "top",
legend.margin = margin(t = 20)
) +
transition_reveal(yearID)
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
animate(p3, height = 600, width = 600)

# anim_save("SLM418/NLC Wins 2000-2019.gif")