Skip to content

Transitioning on generated stats and object permanence #262

@clauswilke

Description

@clauswilke

I think I've discovered another issue with transitioning on generated stats. When trying to use group to manipulate object permanence, the transitions get disrupted.

library(ggplot2)
library(gganimate)
library(ungeviz)  # devtools::install_github("clauswilke/ungeviz")

# this works
ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() +
  stat_smooth_draws(times = 20) + 
  theme_bw() +
  transition_states(stat(.draw), 1, 2)

test

So far so good. Now, when I try to make lines fade in and out rather than transform, I end up with no animation.

# this doesn't
ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() +
  stat_smooth_draws(times = 20, aes(group = stat(.draw))) + 
  theme_bw() +
  transition_states(stat(.draw), 1, 2) +
  enter_fade() + exit_fade()
#> nframes and fps adjusted to match transition

test2

However, things work fine if I do the same with an external data frame rather than a stat.

library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-24. For overview type 'help("mgcv-package")'.
fit <- gam(mpg ~ s(hp), data = mtcars, method = "REML")
newdata <- data.frame(hp = seq(min(mtcars$hp), max(mtcars$hp), length.out = 100))
sample_df <- sample_outcomes(fit, newdata, 10, unconditional = TRUE)

ggplot(mtcars, aes(hp, mpg)) +
  geom_point(color = "grey30", size = 0.5) +
  geom_line(data = sample_df, aes(group = .draw), color = "blue") +
  theme_bw() +
  transition_states(.draw, 1, 2) +
  enter_fade() + exit_fade()

test3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions