Skip to content

Tranistion_layer adds extra layer of NA #384

@mickyallen10

Description

@mickyallen10

When creating a .gif using transition_layer() and extra frame of NA is added at the end.
Reprex:

library(tidyverse)
library(gganimate)

dat1 <- data.frame(expand.grid(id = seq(1,5,1),obs=seq(1,10,1))) %>% 
  mutate(x = runif(50,10,30),
         y = runif(50,100,300))

p <- dat1 %>% 
  ggplot(aes(x,y))+
  geom_point(data=filter(dat1,id==1))+
  geom_point(data=filter(dat1,id==2))+
  geom_point(data=filter(dat1,id==3))+
  geom_point(data=filter(dat1,id==4))+
  geom_point(data=filter(dat1,id==5))

layername <- c("one","two","three","four","five")

anim <- p + transition_layers(
  layer_length = 5,
  transition_length = 1,
  keep_layers = FALSE,
  from_blank = FALSE,
  layer_order = NULL,
  layer_names = layername
)+ 
  ggtitle('Layers',
          subtitle = '{closest_layer} of 5')

anim

The animation works as expected until the end of the animation . The layers go ..."five of 5", "one of 5", "NA of 5", "one of 5".

There is no NA in the layer information:

anim$layers
[[1]]
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[2]]
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[3]]
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[4]]
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[5]]
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

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