如何控制gganimate中闪烁点的外观

时间:2019-10-23 14:26:29

标签: r animation ggplot2 plot gganimate

说我有要用TODO: AS-123 no match todo: as-123 no match fixme: https://jira.company.com/browse/AS-14965 no match fixme: https://jira.company.com fixme as-123 no match todo:as-123 no match todo match todo match todo:match todo :match todo123 todo : match todo: match fixme: match todo: match https://jira.company.com/ + ggplot2制作动画的这些数据。

gganimate

动画/问题的目标是

不。 1.数据集中的每一天+ x + y点都有闪烁的红点(表示该天+ x + y有观测值)。闪烁应该非常简短。闪烁后,它应该变为黑色的背景颜色(由shadow_mark控制)。请注意,我不希望圆点浮动,而只停留在它们所在的位置(请参阅此问题的解决方案:How to make dots in gganimate appear and not transition)。

不。 2.我也希望点开始于一天开始时开始闪烁。这是只执行我想要的部分的代码,但是未能(完全)地址数字1和2:

library(ggplot2)
library(gganimate)

data <- data.frame(day = c(1:5, 1:5), 
    x = c(rep(2,5), rep(4, 5)), 
    y=c(rep(1, 5), rep(2, 5)))

data <- data[c(1:2, 4:10),]

以下是生成的动画:

enter image description here

我希望解决两个问题:

  1. 这些点不仅会瞬时闪烁,而且会闪烁太长时间。换句话说,我希望先看到一个红色的点,然后是黑色的点,然后是红色的点,等等。
  2. 闪光灯开始的时间也有问题。如预期的那样,当点变成黑色(因为ggplot(data, aes(x,y, group=interaction(x,y))) + geom_point(color="red", size=3) + transition_time(day) + shadow_mark(color="black", size=3) + theme(plot.subtitle = element_text(hjust = 0.7)) + labs(subtitle = paste('day: {frame_time}')) -> a anim_save("test.gif", a, end_pause=6, width = 400, height = 450, duration=15) 缺少(x = 2,y = 1)点的第3天)时,可以说明这一点。但是,它在第​​3天途中变黑,而在第4天途中变回红色,但是我希望它在第3天开始时变黑,而在第4天开始时变红。请注意,我不确定这次的对齐是否是由data行为或副标题transition_time行为或其他原因引起的。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

这是一种每天准备处理25帧数据的方法,该方法仅对其中的第一个进行闪烁:

library(dplyr); library(tidyr)
f_per_day <- 25
animate(
  data %>%
    uncount(f_per_day, .id = "frame") %>%
    mutate(time = day + (frame-1)/f_per_day) %>%

    ggplot(aes(x, y, color = frame == 1)) +
    geom_point(size = 3) +
    scale_color_manual(values = c("black", "red"), guide = F) +
    theme(plot.subtitle = element_text(hjust = 0.7)) +      
    labs(subtitle = paste('day: {floor(frame_time*10)/10}')) +
    transition_time(time),

  width = 400, 
  height = 450, 
  fps = 25, 
  type = "cairo")

enter image description here

相关问题