bil*_*999 4 plot r ggplot2 gganimate
我正在使用 gganimate。假设我有这个 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)
Run Code Online (Sandbox Code Playgroud)
我有一个问题:如何才能让新点出现而不是从旧点过渡?换句话说,我只想让新点出现在它们的最终位置并且没有过渡。我应该如何修改代码?
转换最终与每个数据点的group. 在您的代码中,所有第一天的数据点都共享一个组,因此它们显示在旧数据点中。
给这些点自己的组(例如通过使用group = interaction(Month, Day)),它应该可以工作。
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)
Run Code Online (Sandbox Code Playgroud)