I am trying to add a year header to build from a dataset that was launched through tweenr. Following the lead of revolutionanalytics.com
library(tidyverse)
library(tweenr)
library(gapminder)
gapminder_edit <- gapminder %>%
arrange(country, year) %>%
select(gdpPercap,lifeExp,year,country, continent, pop) %>%
rename(x=gdpPercap,y=lifeExp,time=year,id=country) %>%
mutate(ease="linear")
gapminder_tween <- tween_elements(gapminder_edit,
"time", "id", "ease", nframes = 150) %>%
mutate(year = round(time), country = .group) %>%
left_join(gapminder, by=c("country","year","continent")) %>%
rename(population = pop.x)
gapminder_tween %>% arrange(country, .frame) %>% head()
To create a gif, I can use the frame headers (a little pointless) and set title_frame = TRUE(the default) in the function gganimate.
library(gganimate)
library(animation)
p2 <- ggplot(gapminder_tween,
aes(x=x, y=y, frame = .frame)) +
geom_point(aes(size=population, color=continent),alpha=0.8) +
xlab("GDP per capita") +
ylab("Life expectancy at birth") +
scale_x_log10()
magickPath <- shortPathName("C:\\Program Files\\ImageMagick-7.0.6-Q16\\magick.exe")
gganimate(p2, ani.options = ani.options(convert=magickPath), interval = 0.1)

I tried to use the column of the year ( frame = yearin display aesthetics), but this only leads to 56 frames and dots appearing several times in each frame.
p2 <- ggplot(gapminder_tween,
aes(x=x, y=y, frame = year)) +
geom_point(aes(size=population, color=continent),alpha=0.8) +
xlab("GDP per capita") +
ylab("Life expectancy at birth") +
scale_x_log10()

Can I (and if so, how) have the first gif with headers for each frame corresponding to the corresponding values yearin the tween'ed data frame?