How to make dots in gganimate appear and not transition

本秂侑毒 提交于 2019-12-24 10:50:34

问题


I am using gganimate. Say I have this MWE:

library(ggplot2)
library(gganimate)
ggplot(airquality, aes(Day, Temp)) +
    geom_point(color = 'red', size = 1) +
    transition_time(Month) +
    shadow_mark(colour = 'black', size = 0.75)

I have one question: how can I make the new points just appear as opposed to transitioning from the old ones? Put another way, I just want the new dots to appear at their final location and not have a transition. How should I modify the code?


回答1:


The transitions are ultimately tied to each data point's group. In your code, all the Day 1 data points are sharing a group, and so they appear from the old ones.

Give the points their own group (e.g. by using group = interaction(Month, Day)) and it should work.

a <- ggplot(airquality, aes(Day, Temp, 
                            group = interaction(Month, Day))) +
  geom_point(color = 'red', size = 1) +
  transition_time(Month) +
  shadow_mark(colour = 'black', size = 0.75) +
  enter_fade()  # I liked the look of this, but fine to leave out
animate(a, nframes = 100)



来源:https://stackoverflow.com/questions/56411604/how-to-make-dots-in-gganimate-appear-and-not-transition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!