Reputation: 23
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
Using transition_reveal()
doesn't visually preserve the Temp tiles as it traverses along Day.
anim1 <- anim + transition_reveal(Day)
anim1
I also tried this with transition_time()
with no luck.
Thanks for your help!
Upvotes: 2
Views: 477
Reputation: 66765
One possibility here is transiton_manual
:
anim1 <- anim + transition_manual(Day, cumulative = TRUE)
Upvotes: 3
Reputation: 79164
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
Upvotes: 2