【问题标题】:How to make dots in gganimate appear and not transition如何使gganimate中的点出现而不是过渡
【发布时间】:2023-03-28 02:31:01
【问题描述】:

我正在使用 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)

我有一个问题:我怎样才能让新点出现而不是从旧点过渡?换句话说,我只想让新点出现在它们的最终位置而不是过渡。我应该如何修改代码?

【问题讨论】:

    标签: r ggplot2 plot gganimate


    【解决方案1】:

    转换最终与每个数据点的group 相关联。在您的代码中,所有第 1 天数据点都共享一个组,因此它们从旧数据点中显示出来。

    给点他们自己的组(例如通过使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 2019-07-04
      • 2019-05-21
      • 2019-04-06
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多