{gganimate} Points and lines do not follow the same path

Hi together,

I am aiming to create a simple timeline with points in gganimate. However, since hours I cannot get my head around what is wrong with my example. I reduced to be fairly simple but still, lines and points do not take the same path. Moreover, points multiply even though there is only one observation per group per time step (Day). I am also wondering why some points for soem days x groups are kept and others are not which is likely a hint but I cannot figure it out.

Edit: I also tried different eas_aes() but without any obviosu changes in the reuslting animation.

The example provided by @thomasp85, which is more or less the same animation, works like a charm.

What am I missing?

library(tidyverse)
library(gganimate)

structure(
  list(
    Day = c(10L, 10L, 9L, 10L, 9L, 10L, 10L, 10L, 
            9L, 9L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 
            5L, 6L, 6L, 6L, 6L, 7L, 5L, 6L, 5L, 5L, 5L, 5L), 
    Position = c(1L,  2L, 1L, 3L, 2L, 4L, 5L, 6L, 3L, 5L, 1L, 1L, 3L, 4L, 5L, 6L, 7L, 
                 1L, 3L, 4L, 5L, 6L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 8L, 2L, 8L, 3L, 
                 4L, 5L, 6L), 
    Club = c("Borussia M'gladbach", "Borussia Dortmund", 
             "Borussia M'gladbach", "RB Leipzig", "Bayern Munich", "Bayern Munich", 
             "SC Freiburg", "FC Schalke 04", "SC Freiburg", "Borussia Dortmund", 
             "Borussia M'gladbach", "Borussia M'gladbach", "Bayern Munich", 
             "Borussia Dortmund", "RB Leipzig", "RB Leipzig", "FC Schalke 04", 
             "Bayern Munich", "Bayern Munich", "SC Freiburg", "RB Leipzig", 
             "FC Schalke 04", "SC Freiburg", "FC Schalke 04", "RB Leipzig", 
             "RB Leipzig", "SC Freiburg", "FC Schalke 04", "Borussia M'gladbach", 
             "Borussia Dortmund", "Bayern Munich", "Borussia Dortmund", "Borussia Dortmund", 
             "SC Freiburg", "FC Schalke 04", "Borussia M'gladbach")), 
  class = c("tbl_df", "tbl", "data.frame"), 
  row.names = c(NA, -36L)) %>% 
  ggplot(aes(Day, Position, color = Club)) + 
    geom_line(show.legend = F) + 
    geom_point(show.legend = F) + 
    transition_reveal(Day)

Created on 2019-12-19 by the reprex package (v0.3.0)

Thank you and all the best,
Cédric

I'm not sure exactly why this is the solution, but if you sort by Club and Day it works:

structure(
  list(
    Day = c(10L, 10L, 9L, 10L, 9L, 10L, 10L, 10L, 
            9L, 9L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 
            5L, 6L, 6L, 6L, 6L, 7L, 5L, 6L, 5L, 5L, 5L, 5L), 
    Position = c(1L,  2L, 1L, 3L, 2L, 4L, 5L, 6L, 3L, 5L, 1L, 1L, 3L, 4L, 5L, 6L, 7L, 
                 1L, 3L, 4L, 5L, 6L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 8L, 2L, 8L, 3L, 
                 4L, 5L, 6L), 
    Club = c("Borussia M'gladbach", "Borussia Dortmund", 
             "Borussia M'gladbach", "RB Leipzig", "Bayern Munich", "Bayern Munich", 
             "SC Freiburg", "FC Schalke 04", "SC Freiburg", "Borussia Dortmund", 
             "Borussia M'gladbach", "Borussia M'gladbach", "Bayern Munich", 
             "Borussia Dortmund", "RB Leipzig", "RB Leipzig", "FC Schalke 04", 
             "Bayern Munich", "Bayern Munich", "SC Freiburg", "RB Leipzig", 
             "FC Schalke 04", "SC Freiburg", "FC Schalke 04", "RB Leipzig", 
             "RB Leipzig", "SC Freiburg", "FC Schalke 04", "Borussia M'gladbach", 
             "Borussia Dortmund", "Bayern Munich", "Borussia Dortmund", "Borussia Dortmund", 
             "SC Freiburg", "FC Schalke 04", "Borussia M'gladbach")), 
  class = c("tbl_df", "tbl", "data.frame"), 
  row.names = c(NA, -36L)) %>% 
  arrange(Club, Day) %>% 
  ggplot(aes(Day, Position, color = Club)) + 
    geom_line(show.legend = F) + 
    geom_point(show.legend = F) + 
    transition_reveal(Day)
2 Likes

Wow, thanks! I've tried so many things but I didn't came up with this ossible solution Did you know the issue already or how did you? I do't think this is the intended behaviour, going to file an issue on GitHub.

Thanks and all the best,
Cédric

I found it mostly by mistake. I thought maybe the problem was having the same x and along variables. So I made a dummy row number variable, which fixed it. I realized it was the within-group sorting to make the dummy variable that solved the problem when I saw that transition_reveal calls for using the same variable for x and along.

Certainly seems like a bug to me.

I had in mind a grouped tibble and was already celebrating while erasing that line - but I was disappointed. Thanks again, saved me some hours!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.