2

I'm trying to do a scatterplot similar to this one with gganimate in R:

enter image description here

But I can't find any function to do what the legend in the plot added before does.

Does anyone know how can I do a legend similar to that one? The time runs in the legend bar and when the color changes in the bar, also does in the plot background.

If anybody knows which program or language was used to do this plot or knows in which programming language could I do a similar animation, I'll be thankful to you to tell me.

Thanks.

Edit: This is an example of code I've been working with, with the Gapminder dataset. The code I've used to do the animation with gganimate is this one:

  library(ggplot2)
    library(gapminder)
    library(gganimate)
    library(gifski)

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size=pop, 
color=country))+
  geom_point(alpha = 0.6)+
  scale_color_manual(values = country_colors)+
  scale_size(range = c(2,15))+
  scale_x_log10()+
  facet_wrap(~continent)+
  theme_bw()+
  theme(legend.position = 'none')+
  theme(axis.text = element_text(size=20),
        axis.title = element_text(size = 22, face = 'bold'),
        strip.text = element_text(size = 20))+
  labs(title = "Year: {frame_time}", x = "GDP per capita", y = "Life expentancy")+
  transition_time(year)

animate(p, nframes=120,
        renderer = gifski_renderer("Gapminder.gif"),
        height = 700, width = 1000)

So what I want is to do a legend like the bar in the gif plot I added before, where the years pass by in the bar. It also has colors for every time period, and when the color changes in the bar, also does in the plot background.

Mireia
  • 21
  • 4

0 Answers0