Created
October 1, 2021 21:37
-
-
Save FlukeAndFeather/1ee38865c7f8dcc5476c36e23bd64cb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on tutorial: https://gganimate.com/articles/gganimate.html | |
# Accessed 2021-10-01 | |
library(gganimate) | |
# We'll start with a static plot | |
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + | |
geom_point() | |
plot(p) | |
# Animate | |
anim <- p + | |
# Transition between species, spending 1s in each Species and animating for | |
# 2s between states | |
transition_states(Species, | |
transition_length = 2, | |
state_length = 1) + | |
# Use an easing function to make the movement more natural | |
ease_aes('cubic-in-out') + | |
# Add a title so audience knows what they're seeing | |
ggtitle('Species = {closest_state}') | |
# Show in RStudio | |
anim | |
# Save to GIF | |
anim_save("iris_species_animations.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment