Skip to content

Instantly share code, notes, and snippets.

@alistaire47
Created November 28, 2018 04:36
Show Gist options
  • Save alistaire47/2474d87fff05b8fa0813e4d9b977cb57 to your computer and use it in GitHub Desktop.
Save alistaire47/2474d87fff05b8fa0813e4d9b977cb57 to your computer and use it in GitHub Desktop.
uptake gifs
library(dplyr)
library(ggplot2)
library(gganimate)
### Horizontal rotation
p <- data_frame(x = c(-4, 0, 4), y = c(0, 3, 0), state = 1) %>%
bind_rows(mutate(., x = -x, state = 2)) %>% # frame flipped over y-axis
ggplot(aes(x, y, ymin = y, ymax = y + 1)) +
geom_ribbon() +
coord_equal() +
theme_void() +
transition_time(state) +
ease_aes('sine-in-out')
animate(p, nframes = 100, fps = 30, height = 250)
anim_save('uptake.gif')
### Vertical flip
p2 <- data_frame(x = c(-4, 0, 4), y = c(-1.5, 1.5, -1.5), state = 1) %>%
bind_rows(mutate(., y = -y, state = 2)) %>% # frame flipped over y-axis
bind_rows(mutate(slice(., seq(n() / 2)), state = 3)) %>% # back to start
ggplot(aes(x, y, ymin = y, ymax = y + 1)) +
geom_ribbon() +
coord_equal() +
theme_void() +
transition_time(state) +
ease_aes('quartic-in-out')
animate(p2, nframes = 100, fps = 30, height = 250)
### Flip both
p3 <- data_frame(x = c(-4, 0, 4), y = c(-1.5, 1.5, -1.5), state = 1) %>%
bind_rows(mutate(., x = -x, y = -y, state = 2)) %>% # frame flipped over y-axis
bind_rows(mutate(slice(., seq(n() / 2)), state = 3)) %>% # back to start
ggplot(aes(x, y, ymin = y, ymax = y + 1)) +
geom_ribbon() +
coord_equal() +
theme_void() +
transition_time(state) +
ease_aes('sine-in-out')
animate(p3, nframes = 100, fps = 30, height = 250)
@alistaire47
Copy link
Author

uptake

@alistaire47
Copy link
Author

p <- data_frame(x = c(-2, 0, 2), y = c(0, 2, 0), state = 1) %>% 
    bind_rows(mutate(., x = -x, state = 2)) %>%    # frame flipped over y-axis
    ggplot(aes(x, y, ymin = y, ymax = y + 1)) + 
    geom_ribbon() + 
    coord_equal() + 
    theme_void() + 
    transition_time(state) + 
    ease_aes('sine-in-out')

animate(p, nframes = 60, fps = 30)

spinning-uptake-big

@alistaire47
Copy link
Author

spinning-uptake-gray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment