transition_reveal - disappearing point
py9mrg opened this issue · 2 comments
Hello,
I am using transition_reveal
to show changes in x, y values by a third value z, using geom_point
. My problem arises from the fact that the last few frames at the end of the animation (and sometimes the first frame) are blank frames that don't show the points, as per here:
library(tidyverse)
library(gganimate)
data <- tibble(
x = rep(1:10, 3),
y = 1:30,
z = rep(1:10, 3),
category = c(rep("A", 10), rep("B", 10), rep("C", 10))
)
p <- ggplot(data, aes(x, y, colour = category)) +
geom_point()
anim_reveal <- p +
transition_reveal(z, keep_last = FALSE)
animate(anim_reveal, renderer = gifski_renderer(loop = FALSE))
It might seem a more natural fit to use transition_states
or transition_time
instead and it's true that these never introduces blank frames, but they only works when the x and y values exist in every z state (which is not the case in my data), otherwise the points flash in and out:
data$z <- data$z + rnorm(30)
p <- ggplot(data, aes(x, y, colour = category)) +
geom_point()
anim_states <- p +
transition_states(z, wrap = FALSE)
animate(anim_states, renderer = gifski_renderer(loop = FALSE))
Currently my options are:
- stick with
transition_reveal
and usesplit_animation
to remove the frames without the points (I will post another issue as I've noticed a weird gremlin aboutsplit_animation
), or - modify my data to force all x,y-values to exist in all z-states - but this requires a fair bit of wrangling - and then use
transition_states/time
I was hoping there might be a way to prevent transition_reveal
from introducing these blank frames, but I can't work it out?
Sorry, I've been fighting with this for a couple of days and as soon as I post the issue I work out the answer... transition_components
:
library(tidyverse)
library(gganimate)
data <- tibble(
x = rep(1:10, 3),
y = 1:30,
z = rep(1:10, 3),
category = c(rep("A", 10), rep("B", 10), rep("C", 10))
)
p <- ggplot(data, aes(x, y, colour = category)) +
geom_point()
anim_reveal <- p +
transition_components(z)
animate(anim_reveal, renderer = gifski_renderer(loop = FALSE))
Edit: although, interestingly, even transition_components
has a similar problem - sometimes introducing blank frames. Not in the simplified case above, but in my real world use case I get the first frame as a blank, but not the last (so it's now ok for my use). I'll reopen as I'm not sure this is expected behaviour, but if it is then feel free to close.
Reopening in light of edit to above comment - the blank frames still exist even with transition_components
, it's just now only the first frame (at least in my case). I don't seem to be able to induce the problem with the simplified data here though, so it might be an edge case of my specific data.
Edit: in my case it seems like combining transition_components
with view_zoom_manual
when wrap = FALSE
is the culprit. But I can't reproduce it with the simple data above.