Search code examples
rggplot2gganimategeom-tile

How can I use gganimate with geom_tile?


I was having trouble animating a geom_tile() plot where the tile remains visible after it appears.

Here's my code using the airquality data.

First, the static plot. Here, the x-axis is Day. The y-axis is Month and Temp is the fill.

library(gganimate) 

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

anim

Static Tile Plot enter image description here

Using transition_reveal() doesn't visually preserve the Temp tiles as it traverses along Day.

anim1 <- anim + transition_reveal(Day)
anim1

Animated Tile Plot

I also tried this with transition_time() with no luck.

Thanks for your help!


Solution

  • One possibility here is transiton_manual:

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

    enter image description here