I am trying to recreate an old code I had that used to work perfectly. I am trying to animate my graph, it comes out fine as a static graph, but the animation gives me the error: Error in match.fun(FUN) : 'scales$transform_df' is not a function, character or symbol. Here is my code from start to finish:
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(ggplot2)
library(gganimate)
library(ggthemes)
library(lubridate)
library(readr)
nbaallelo <- read_csv("~/nbaallelo.R")
View(nbaallelo)
nba_df <- nbaallelo
nba_df <- nba_df %>% select(-c('_iscopy', notes, gameorder, elo_n, opp_elo_n, win_equiv))
nba_final <- nba_df %>% mutate(result = case_when(game_result == "W" ~ 1,
game_result == "L" ~ 0)) %>%
mutate(date_game = mdy(date_game),
month = month(date_game, label = TRUE),
weekday = wday(date_game, label = TRUE)) %>%
select(-game_result)
Top 5 Teams from 2000-2015:
top5 <- filter(nba_df, fran_id == "Heat" | fran_id == "Bulls" | fran_id == "Lakers" | fran_id == "Spurs" | fran_id == "Magic")
top5 <- filter(top5, year_id == "2000" | year_id == "2001" | year_id == "2002" | year_id == "2003" | year_id == "2004" | year_id == "2005" | year_id == "2006" | year_id == "2007" | year_id == "2008" | year_id == "2009" | year_id == "2010" | year_id == "2011" | year_id == "2012" | year_id == "2013" | year_id == "2014" | year_id == "2015")
top5 <- filter(top5, seasongame == "1")
Static Graph:
p <- ggplot(
top5,
aes(x = year_id, y = pts, colour = fran_id)
) +
geom_line(show.legend = TRUE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2,12)) +
scale_x_log10() +
theme_fivethirtyeight() +
labs(x = "Year", y = "Points")
p
Animated Graph:
p <- ggplot(
top5,
aes(x = year_id, y = pts, colour = fran_id)
) +
geom_point(show.legend = TRUE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2,12)) +
scale_x_log10() +
theme_fivethirtyeight() +
labs(x = "Year", y = "Points")
p + transition_time(year_id) +
labs(title = "Year: {frame_time}")
I ensured that R was updated, as were the packages.