如何使gganimate中的点出现而不过渡 [英] How to make dots in gganimate appear and not transition
问题描述
我正在使用gganimate.说我有这个MWE:
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?
推荐答案
转换最终与每个数据点的 group
相关.在您的代码中,第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.
将点赋予自己的组(例如,通过使用 group =交互(月,日)
),它应该可以工作.
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)
这篇关于如何使gganimate中的点出现而不过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!