Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting two transition_time() classes with different starting times in one gganimate plot #379

Open
Marnolean opened this issue Mar 26, 2020 · 0 comments
Labels

Comments

@Marnolean
Copy link

I am recreating the sankey diagram from https://www.hvitfeldt.me/blog/recreate-sankey-flow-chart/ but the APIs have changed in the mean time and now I am struggling with the following:

In the sankey diagram, the dots (or points) move toward the boxes shown on the right-hand side and the boxes fill up as the dots reach them. I am using transition_time() to make the dots move from left to right starting at the very beginning of the animation (this is shown in the original code by Emil). As the dots reach the boxes the boxes should start to fill up. Since there is a passage of time between when the dots first appear and when they hit the boxes, the animation depicting the filling up of the boxes should of course start at a later stage. I am using transition_time() in conjunction with shadow_mark() to fill up the boxes.

The animation of the points is done in the context of a data frame (point_data) with a time column running from 2 to 500. The data frame used for filling up the boxes (end_lines) has a time column starting with a value of 101.

In this example, the first dot appears top left at time=2 and hits the first box at time=101. Therefore, I want the transition time for the `end lines' (the lines filling up the boxes) to start at t=101 while the transition_time for the dots should start at t=2 already. I have tried to use the range parameter on the end-lines transition_time() so as to start from time=101 but that then overwrites the first transition_time() for the dots and essentially my animation starts at t=101. In other words, it skips the whole first portion of the animation. If I do not incorporate the range parameter, the trajectory and timing of the dots are correct but the boxes start to fill up instantaneously (in other words before the dots reach the box).

ggplot() +
  geom_point(data=point_data,mapping=aes(x, y, color = color),shape = 15) +
  transition_time(time) + 
  geom_path(data = ending_box,
            aes(x, y, group = id, color = "grey70")) +
  theme_void() +
  coord_cartesian(xlim = c(-0.05, 1.15)) +
  guides(color = "none",fill="none") +
  geom_polygon(data=end_lines, mapping=aes(x=x, y=y,fill=color, group=id)) +
  transition_time(time)+
  shadow_mark(exclude_layer = c(1,2))

Is it even possible to do two transition_times() in one plot?
A potential, though undesirable, workaround might be to pad the top of the end-lines data frame with dummy data that runs from time 2 to 100? Also looked at transition_components() - not sure if it can work but it does not support geom_polygon currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants