Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

End Animation after Appearing

Tags:

r

gganimate

I made an animation from my data and managed to give it a good seize/resolution for a powerpoint presentation.

I would like the bars in the barchart to appear and then end the animation. I can't find the proper settings in gganimate to make the animation only run in one direction (appear-only).

    a <- data.frame(group = c("sehr schlecht",
                          "schlecht",
                          "weder noch",
                          "gut",
                          "sehr gut"),
                values = c(0, 0, 0, 0, 0),
                frame = rep("a", 5))

b <- data.frame(group = c("sehr schlecht",
                          "schlecht",
                          "weder noch",
                          "gut",
                          "sehr gut"),
                values = c(20,
                          40,
                          20,
                          5,
                          15),
                frame = rep("b", 5))

graphdata <- rbind(a,b)  

p <- ggplot(graphdata, aes(x=group, y=values, fill=group)) + 
  geom_bar(stat='identity') +
  ylim(0, 100) +
  theme_bw() +
  theme(legend.title=element_blank()) +
  scale_x_discrete(name ="Anteil (%)", 
                   limits=c("sehr schlecht",
                            "schlecht",
                            "weder noch",
                            "gut",
                            "sehr gut")) +
  # gganimate specific bits:
  transition_states(
    frame,
    transition_length = 2,
    state_length = 1
  ) +
  ease_aes('sine-in-out')

options(gganimate.dev_args = list(width = 800, height = 600, res = 150))
                           
animate(p + enter_appear(),
  renderer = av_renderer()
)
like image 435
BanffBoss122 Avatar asked Oct 17 '25 21:10

BanffBoss122


1 Answers

Okay, found it myself! Ending an animation after it ran can be toggled with the transitions states (wrap = FALSE):

  # gganimate specific bits:
  transition_states(
    frame,
    transition_length = 2,
    state_length = 1,
    wrap = FALSE
  ) +
  ease_aes('sine-in-out')
like image 104
BanffBoss122 Avatar answered Oct 19 '25 13:10

BanffBoss122



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!