Created
August 23, 2018 09:29
-
-
Save djnavarro/ae0a789e8121c366aba93c1b44e346d6 to your computer and use it in GitHub Desktop.
thank you animation
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
library(tidyverse) | |
library(gganimate) | |
# initial frame | |
last_tbl<- tibble( | |
letter = c("T","H","A","N","K","Y","O","U"), | |
x_pos = c(1,2,3,4,5,2,3,4), | |
y_pos = c(3,3,3,3,3,2,2,2), | |
id = 1:8, | |
fr = 0.5 | |
) | |
tbl <- last_tbl | |
f <- 0.5 | |
for(i in 1:3) { | |
# move in x-dim | |
tbl2 <- last_tbl %>% mutate( | |
fr = f+1, | |
x_pos = x_pos + sample(x = c(-1,0,1), size = 8, replace = TRUE) | |
) | |
# move in y-dim | |
tbl3 <- tbl2 %>% mutate( | |
fr = f+2, | |
y_pos = y_pos + sample(x = c(-1,0,1), size = 8, replace = TRUE) | |
) | |
# bind | |
tbl <- bind_rows(tbl, tbl2, tbl3) | |
# next step | |
last_tbl <- tbl3 | |
f <- f+2 | |
} | |
# time symmetry | |
tbl2 <- tbl | |
tbl2$fr <- -tbl2$fr | |
tbl <- bind_rows(tbl, tbl2) | |
m <- min(tbl$fr) | |
tbl$fr <- tbl$fr - m + 1 | |
tbl <- tbl %>% arrange(fr,id) | |
# animation | |
p <- tbl %>% | |
ggplot(aes(x = x_pos, y = y_pos)) + | |
geom_point(size = 20, alpha = .2, colour = "purple", show.legend = FALSE) + | |
geom_text(aes(label = letter), size = 8, show.legend = FALSE) + | |
ylim(0, 5) + | |
xlim(0, 6) + | |
xlab("") + ylab("") + | |
theme(axis.title.x=element_blank(), | |
axis.text.x=element_blank(), | |
axis.ticks.x=element_blank()) + | |
theme(axis.title.y=element_blank(), | |
axis.text.y=element_blank(), | |
axis.ticks.y=element_blank()) + | |
transition_states(fr, 1, 1, wrap = TRUE) + | |
ease_aes('linear') | |
# create | |
animate(p) | |
anim_save("~/Desktop/thankyou.gif") | |
Author
djnavarro
commented
Aug 23, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment