library(tidyverse)
library(dplyr)
library(Lahman)
library(ggplot2)
library(plotly)
library(htmlwidgets)
library(ggthemes)
library(ggimage)
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.1.2
MLB_Team_Logo <- read.csv("SLM418/team_logo.csv")
#view(MLB_Team_Logo)
NLcentralteams <- filter(Teams, lgID == "NL" & divID == "C" & yearID >=2000 & yearID <=2009)%>%
filter(teamID != "HOU")
MLB_Team_Logo$teamID[MLB_Team_Logo$teamID =="STN"] <- "STL"
MLB_Team_Logo$teamID[MLB_Team_Logo$teamID =="CHN"] <- "CHC"
#view(MLB_Team_Logo)
problem1 <- merge(x=NLcentralteams, y=MLB_Team_Logo, by.x="franchID", by.y = "teamID")
#view(problem1)
#problem1$yearID <- as.numeric(problem1$yearID)
plot1 <- ggplot(problem1, aes(R, W))+
geom_image(aes(image=logo), size=.1)+
labs(title = 'Season: {frame_time}', x = "Runs Scored", y = "W") +
theme_classic()+
transition_time(problem1$yearID)+
ease_aes()
plot1

#animate(plot1, duration = 30, fps = 10)
NLC2 <- filter(Teams, lgID == "NL" & divID == "C" & yearID >=2000 & yearID <=2019)%>%
filter(teamID != "HOU")
#view(NLC2)
plot2 <- ggplot(NLC2, aes(yearID,W, color=franchID))+
geom_line()+
theme_economist()+
labs(title = "Team Performance in NLC 2000-2019", x="Seasons", y="Wins")+
transition_reveal(along = yearID)
#ease_aes()
plot2

#animate(plot1, duration = 30, fps = 10)