I can't use transitions from the gganimate package due to how I've set up my colors from group to group. My data is organized by Team, Season, Rank, Primary color, Secondary Color:
Team,Season,Rank,Primary,Secondary
Washington Wizards,1998,16,#e31837,#002B5C
Washington Wizards,1999,24,#e31837,#002B5C
Washington Wizards,2000,24,#e31837,#002B5C
Utah Jazz,1998,2,#F9A01B,#002B5C
Utah Jazz,1999,5,#F9A01B,#002B5C
Utah Jazz,2000,5,#F9A01B,#002B5C
Toronto Raptors,1998,28,#BA0C2F,#753BBD
Toronto Raptors,1999,19,#BA0C2F,#753BBD
Toronto Raptors,2000,9,#BA0C2F,#753BBD
San Antonio Spurs,1998,5,#000000,#c4ced4
San Antonio Spurs,1999,1,#000000,#c4ced4
San Antonio Spurs,2000,9,#000000,#c4ced4
Sacramento Kings,1998,23,#63727A,#5a2d81
Sacramento Kings,1999,9,#63727A,#5a2d81
Sacramento Kings,2000,9,#63727A,#5a2d81
And my current code:
library(ggplot2)
library(gganimate)
library(transformr)
library(dplyr)
df <- read.csv('NBARH_mini.csv')
df$Primary <- as.character.factor(df$Primary)
df$Secondary <- as.character.factor(df$Secondary)
df_sort <-arrange(df,Team)
PPalette <- c(df_sort$Primary[c(1,4,7,10,13)])
SPalette <- c(df_sort$Secondary[c(1,4,7,10,13)])
TPalette <- c(PPalette,SPalette)
p <- ggplot(df_sort, aes(x = Season, y = Rank)) +
geom_point(aes(colour = Team), size = 3, shape = 21, fill = df_sort$Secondary)+
geom_line(aes(group = Team, color = Team))+
scale_y_reverse()
p <- p + scale_colour_manual(values= PPalette)+
scale_fill_manual(values = SPalette, aesthetics = "fill")
p
anim <- p +
transition_states(Team,
transition_length = 5,
state_length = 5)+
ease_aes('quadratic-in-out')+ # Slow start and end for a smoother look
ggtitle('NBA Season ending rank since Jordan',
subtitle='Ranking History of the {closest_state}')
animate(anim +
enter_fade() +
exit_shrink(),
nframes = 50,
width = 500,
height =400)
My goal is to have a line plot and point plot for each team where the lines are the primary color and the points are filled with the secondary color. I spent a bunch of time trying to hack that together for just a plot trying lots of different methods. The only thing I could do to make it work is to pass df_sort$Secondary
into geom_point() and I've been told that's a "NoNo", but I can't get it to plot otherwise.
And now that I've got that working I get
Error: identical(classes, col_classes(to)) is not TRUE
when I try to animate when using enter_fade()+exit_shrink()
. It will animate with/without those, but with no transitions. Here's what it looks like currently.
https://gfycat.com/NervousComposedGrayfox
Anyone have any experience with this?