如何将 gganimate 与 geom_tile 一起使用?

问题描述

我在为 geom_tile() 绘图设置动画时遇到问题,其中磁贴出现后仍然可见。

这是我使用 airquality 数据的代码

首先是静态图。这里,x 轴是天。 y 轴是月份,温度是填充。

library(gganimate) 

anim <- ggplot(airquality,aes(x = Day,y = Month,fill = Temp)) +
  geom_tile()

anim

静态图块图

enter image description here

使用 transition_reveal() 不会在沿着 Day 遍历时在视觉上保留 Temp 磁贴。

anim1 <- anim + transition_reveal(Day)
anim1

Animated Tile Plot

我也用 transition_time() 尝试过,但没有成功。

感谢您的帮助!

解决方法

这里的一种可能性是transiton_manual

anim1 <- anim + transition_manual(Day,cumulative = TRUE)

enter image description here

,

您可以使用 transition_time()shadow_mark()

library(gganimate) 

anim <- ggplot(airquality,aes(x = Day,y = Month,fill = Temp)) +
  geom_tile()+ 
  transition_time(Day) +
  shadow_mark()
anim

enter image description here