2

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!

tjebo
  • 21,977
  • 7
  • 58
  • 94
FR_Data
  • 23
  • 3

2 Answers2

3

One possibility here is transiton_manual:

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

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
2

You can achieve this with transition_time() and 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

TarJae
  • 72,363
  • 6
  • 19
  • 66
  • Thank you so much for your help, TarJae! – FR_Data Feb 20 '21 at 06:44
  • You are welcome. Please if the answer was helpful then vote up and accept as answer (left top to the answer). Thanks. – TarJae Feb 20 '21 at 07:24
  • 1
    Similarly, if you find the OP post good, then you could upvote their post as well. That's not only kind, but also you will not receive reps unless their reputation has a certain level. – tjebo Feb 20 '21 at 11:07
  • @tjebo. Thank you for this valuable tip. I hadn't considered that yet. – TarJae Feb 20 '21 at 11:43