I've created a gif using gganimate that shows NBA players regular season points per game and compares it to their points per game in the playoffs. I have everything working except i have a graphical issue with shadow_mark()
. The gif starts at the playoffs, transitions to the regular season mark, and then transitions back to playoffs mark.
I want shadow_mark()
to keep the playoffs mark on the graph at all times with 50% opacity like i have it right now. I don't want the regular season mark to stay on the graph, but I don't know how to get rid of it. I've tried various combinations of past = TRUE
and future = FALSE
etc in shadow_mark()
but it doesn't seem to have solved it. I've also tried exclude_layer = 1
but then that deletes both of the shadows instead of just the 1.
Here is my gif as of right now. Below is the code used to create it.
j <- ggplot(nba2, aes(x = PPG, y = Player)) +
geom_point(shape = 21, stroke = 1, aes(fill = Tm, size = 2)) +
theme(legend.title = element_blank(), legend.position = 'none') +
xlab("Points Per Game") +
labs(caption = 'Data via basketball-reference.com')
plot(j)
anim <- j +
transition_states(Playoff_or_reg,
transition_length = 2,
state_length = 2,
wrap = TRUE) +
shadow_mark(past = TRUE, future = FALSE, alpha = 0.5) +
ggtitle("{closest_state}")
anim
Any help on how to fix this issue would be appreciated!
What you wanna do is create a new variable that equals each player's PPG in the regular season. That variable is going to be your static, transparent point. The original variable is the one that is going to transition.
Here's what the code for that viz might look like:
df %>%
ggplot(aes(x = Player, y = PPG, color = Tm, fill = Tm)) +
geom_point(size = 4.5, shape = 21, alpha = 1, stroke = 1) +
geom_point(size = 4.5, shape = 21, alpha = .2, stroke = 1, aes(fill = Tm, color = Tm, x = Player, y = newPPG)) +
coord_flip() +
theme(legend.position = 'none') +
transition_states(
Playoff_or_reg,
transition_length = 1,
state_length = 2)
Hope that helps