0

I am trying to use ggplotly to animate some points through time. The time intervals are of variable length, however, and it seems that plotly's default behavior is to set equal spacing on the animation slider for each given frame. This is undesirable, as the constant spacing misrepresents the duration of time in the dataset.

I haven't been able to figure out whether there is any way to change this. Is it possible to customize the spacing between steps on the animation slider—and, perhaps, the duration between each step?

Simple example:

x <- tribble(
    ~x, ~y, ~t,
    1, 1, 1,
    2, 2, 2,
    4, 4, 4
)
g <- ggplot(x, aes(x, y)) +
    geom_point(aes(frame=t))

ggplotly(g)

Output image In this example, time 4 is just as close to time 2 as 2 is to 1.

The best workaround-ish I can think of right now is to duplicate data in all the right places to synthetically ensure that there actually is equal spacing between times/frames. This is still suboptimal, since then it would make the data appear to jump unrealistically every time the frame transitions from a synthetic time to an observed one.

covert
  • 51
  • 3

1 Answers1

1

If you're just after an animation that interpolates between your frames, you can do so using gganimate. It's not the same functionality as plotly (it's essentially a gif), but will display in the way you've attempted in your example.

library(gganimate)

g2 <- ggplot(x, aes(x, y)) +
  geom_point() +
  labs(title = "t = {frame_time}") +
  transition_time(t)

animate(g2)
conor
  • 1,204
  • 1
  • 18
  • 22
  • Thank you! The interactivity of plotly is a big attractor (this visualization is going towards some interactive html), but it's really helpful to know that gganimate can be an alternative that does vary its transition times. – covert Dec 17 '20 at 06:24