I am trying to plot the top 3 NHL scorers over time using gganimate. Currently, I have a column chart where the x axis shows player names and the y axis shows number of goals for each player. Here's a static version of what I have:
library(ggplot2)
data <- data.frame(name=c("John","Paul","George","Ringo","Pete","John","Paul","George","Ringo","Pete"),
year = c("1997", "1997", "1997", "1997", "1997", "1998", "1998","1998","1998", "1998"),
goals = c(50L, 35L, 29L, 5L, 3L, 3L, 5L, 29L, 36L, 51L))
data <- data %>%
arrange(goals) %>%
group_by(year) %>%
top_n(3, goals)
ggplot(data,
aes(x = reorder(name, goals), y=goals)) +
geom_col() +
facet_wrap(data$year) +
coord_flip()
What I want is to ONLY display the top 3 players. In other words, players who are in the top 3 one year but drop out of the top three the next year should not be shown on the second frame. The final product should look something like this:

