仅阴影一个层/层的带有阴影标记的transition_time

时间:2020-09-20 15:48:58

标签: r ggplot2 gganimate

我相信下面的图片应该很容易解释。使用transition_time时,有没有人知道如何仅为一个几何图形创建阴影标记(用于标记)?

非常欢迎任何解决方法。在一个正常的世界中,我会创建两个图(图和标题),但我不知道如何在这样的组合图上使用gganimate,至少我没有找到关于Cowplot和拼凑而成的解决方案(鉴于至少拼凑而成的人是同一位开发人员,我认为这可能可行。)

library(ggplot2)
library(gganimate)

myfoo <- data.frame(time = 1:100, x = 1:100, y = 1)

p <- 
  ggplot(myfoo) +
  geom_point(aes(x, y)) +
  geom_text(aes(x = 0, y = 0, label = time))

p_anim <- 
  p +
  transition_time(time) +
  shadow_mark()

animate(p_anim, height = 150, width = 250)

左下方的标签不应带有阴影标记。

我正在寻找的东西如下:

p_title <- 
  ggplot(myfoo) +
  geom_point(aes(x, y)) +
  labs(title = "{frame_time}")

p_title_anim <- 
  p_title +
  transition_time(time) +
  shadow_mark()

animate(p_title_anim, height = 150, width = 250)

标题中的交互式元素应该是情节注释。

1 个答案:

答案 0 :(得分:2)

如Z.Lin在她的评论中所建议的,此处是exclude_layer中带有shadow_mark()参数的解决方案:

为了不将其标记为未答复,我将接受它。我仍然希望Z.Lin可以发表她的评论作为答案。

library(ggplot2)
library(gganimate)

myfoo <- data.frame(time = 1:100, x = 1:100, y = 1)

p <- 
  ggplot(myfoo) +
  geom_point(aes(x, y)) +
  geom_text(aes(x = 0, y = 0, label = time))

p_anim <- 
  p +
  transition_time(time) +
  shadow_mark(exclude_layer = 2)

animate(p_anim, height = 150, width = 250)

reprex package(v0.3.0)于2020-10-03创建

相关问题