I have been trying to figure out this for days, but I cannot understand what I am missing. gganimate does not seem to add any transition between frames.
I am using the Tour de France dataset from the tidytuesday. From this, I made a dataframe with the winner's country over the years. I have the cumulative number of victories for each year and added the rank of each country for that year. There are 106 editions, from 1 to 106, and 106 years (from 1903 to 2019, with some gaps due to WWs).
EDIT: Dataset in CSV available: https://github.com/AScalco/AS_TidyTuesday
> head(race_chart_ranked, 20)
# A tibble: 20 x 5
# Groups: year [2]
nationality n.victories edition year rank
<chr> <int> <dbl> <dbl> <int>
1 France 1 1 1903 1
2 Luxembourg 0 1 1903 2
3 Belgium 0 1 1903 3
4 Italy 0 1 1903 4
5 Switzerland 0 1 1903 5
6 Spain 0 1 1903 6
7 Netherlands 0 1 1903 7
8 United States 0 1 1903 8
9 Ireland 0 1 1903 9
10 Denmark 0 1 1903 10
11 Germany 0 1 1903 11
12 Australia 0 1 1903 12
13 Great Britain 0 1 1903 13
14 Colombia 0 1 1903 14
15 France 2 2 1904 1
16 Luxembourg 0 2 1904 2
17 Belgium 0 2 1904 3
18 Italy 0 2 1904 4
19 Switzerland 0 2 1904 5
20 Spain 0 2 1904 6
> tail(race_chart_ranked, 20)
# A tibble: 20 x 5
# Groups: year [2]
nationality n.victories edition year rank
<chr> <int> <dbl> <dbl> <int>
1 Switzerland 2 105 2018 9
2 Australia 1 105 2018 10
3 Denmark 1 105 2018 11
4 Germany 1 105 2018 12
5 Ireland 1 105 2018 13
6 Colombia 0 105 2018 14
7 France 36 106 2019 1
8 Belgium 18 106 2019 2
9 Spain 12 106 2019 3
10 Italy 10 106 2019 4
11 United States 10 106 2019 5
12 Great Britain 6 106 2019 6
13 Luxembourg 5 106 2019 7
14 Netherlands 2 106 2019 8
15 Switzerland 2 106 2019 9
16 Australia 1 106 2019 10
17 Colombia 1 106 2019 11
18 Denmark 1 106 2019 12
19 Germany 1 106 2019 13
20 Ireland 1 106 2019 14
I made this plot and it works fine, except that it does not work smoothly. I already tried to change the number of duration, frames and fps, but it does change much. I tryed by adding "ease_aes()", but it did not produced any change. What I missing?
animation_ranked <- race_chart_ranked %>%
ggplot(aes(xmin = 0, xmax = n.victories, ymin=rank-.5, ymax=rank+0.5, y=rank)) +
geom_rect(fill = "black", color="black", size=1.05) +
scale_x_continuous(limits=c(-15, 40), breaks=c(seq(0, 40, by=5))) +
# Add labels to each country
geom_text(aes(label=nationality, x=(-2.5), hjust="right"), size = 6, fontface="bold") +
# Add a label with the year
geom_text(aes(label=year, x=35, y=13.5), size=15) +
# Add number of victories (if more than 0) for each country
geom_text(data=race_chart_ranked %>% filter(n.victories > 0),
aes(label=n.victories, x=n.victories-0.75, y=rank), color="white", fontface="bold") +
# Reverse the scale to show the highest victories on top
scale_y_reverse() +
# Add labels
labs(title = "Number of victories by country",
x = "Number of victories", y = "") +
# Choose theme
theme_void() +
# ANIMATION CODE
# Group by year
aes(group = year) +
# Apply transition by time
transition_time(year) +
# Apply ease_eas()
ease_aes()
# Set animation general options
options(gganimate.nframes = 100, gganimate.fps = 20)
# Animate and other options
animate(animation_ranked, end_pause=10, duration = 15)