Display different time elements at different speeds in gganimate

后端 未结 1 1157
广开言路
广开言路 2020-12-12 03:16

Using the code from this answer, How to make dots in gganimate appear and not transition, as a MWE, say we have this gganimate:

library(ggplot2)
library(ggan         


        
相关标签:
1条回答
  • 2020-12-12 03:41

    This is my rudimentary try by making a helper column which can be used as our transition_time to show how we can have different time step but desired labels.

    You can later spend some more time to make a better *timestep columns which is more sophisticated and precisely meets your needs.

    The main idea/point here is that we can use functions on the frame_time to get the labels as needed while the transition_time can be manipulated.

    library(ggplot2)
    library(gganimate)
    library(dplyr)
    
    g <- airquality %>%
      group_by(Month) %>%
      mutate(timestep = if_else(Month==5, ((1:n())-1)/2 + Month, 15 + Month)) %>%
      ggplot(aes(Day, Temp, group = interaction(Month, Day))) +
      geom_point(color = 'red', size = 1) +
      transition_time(timestep) +
      shadow_mark(colour = 'black', size = 0.75) +
      enter_fade() +
      labs(title = 'Month: {if_else(frame_time<21,5, ceiling(frame_time-15))}')
    
    animate(g, nframes = 100)
    

    Created on 2019-06-02 by the reprex package (v0.3.0)

    0 讨论(0)
提交回复
热议问题