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

Transitioning on generated stats and object permanence #262

Closed
clauswilke opened this issue Jan 4, 2019 · 6 comments
Closed

Transitioning on generated stats and object permanence #262

clauswilke opened this issue Jan 4, 2019 · 6 comments

Comments

@clauswilke
Copy link
Contributor

@clauswilke clauswilke commented Jan 4, 2019

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

@thomasp85 thomasp85 closed this in 943b4b3 Jan 4, 2019
@clauswilke
Copy link
Contributor Author

@clauswilke clauswilke commented Jan 4, 2019

Transitions work now but there is no fade. Is this another bug or am I missing something?

library(ggplot2)
library(gganimate)
library(ungeviz)

ggplot(mtcars, aes(disp, mpg)) +
  geom_point() +
  stat_smooth_draws(size = 0.5, aes(group = stat(.draw))) +
  theme_bw() +
  transition_states(stat(.draw), 1, 2) +
  enter_fade() + exit_fade()

test

@thomasp85
Copy link
Owner

@thomasp85 thomasp85 commented Jan 4, 2019

That is a separate issue with how geom_smooth encodes its data... the alpha value is only used for the ribbon, not the line.

I'll special-case geom_smooth to make it work as expected... in the meantime you can use enter_grow()/exit_shrink() for a similar effect...

@thomasp85
Copy link
Owner

@thomasp85 thomasp85 commented Jan 4, 2019

Fixed in bd551c1

@clauswilke
Copy link
Contributor Author

@clauswilke clauswilke commented Jan 4, 2019

Nice. Alternatively, these also work:

+ exit_recolour(colour = "#FFFFFF00") + enter_recolour(colour = "#FFFFFF00")

@thomasp85
Copy link
Owner

@thomasp85 thomasp85 commented Jan 4, 2019

yup, except it will block out the grid lines (barely perceptible, but still)

@thomasp85
Copy link
Owner

@thomasp85 thomasp85 commented Jan 4, 2019

oh, wait — you added an alpha to the colour... yeah that'll work

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

Successfully merging a pull request may close this issue.

None yet
2 participants