0

In this example if you run you get a nice standard animation which has been used a lot. Also, showing at the top "Frame n of N". But what if you want it simply to say something in a string? e.g. have it read Str <- c('A', 'B', 'C',...) Obviously you would have to make sure the string length matches the number of frames. Is this possible?

p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + 
  geom_point()
p

anim <- p + transition_states(Species,
                      transition_length = 2,
                      state_length = 1)  

anim + ggtitle('Frame {frame} of {nframes}') 
user3456588
  • 609
  • 4
  • 9

1 Answers1

0

Is this what you are looking for?

library(ggplot2)
library(gganimate)
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + 
  geom_point()
anim <- p + transition_states(Species,
                              transition_length = 2,
                              state_length = 1) +
  labs(title = 'Title : {closest_state}')
anim
user63230
  • 4,095
  • 21
  • 43
  • I don't think so. It's too restricted. I simply want a customisable string. There are 150 frames so let's say str <- c("A", "B", "C", ... , "ES", "ET"). That would be 150 characters that would go over each frame. – user3456588 Feb 12 '20 at 18:16
  • i get you, i think the closest thing is this: https://stackoverflow.com/questions/53864892/gganimate-include-additional-variable-other-than-states-level-variable-or-frame – user63230 Feb 12 '20 at 18:22
  • I think this is exactly what I'm looking for! I have to go for a while so will double check later. Thanks! – user3456588 Feb 12 '20 at 18:28