Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IBS Logo Animation
library(gganimate)
library(tidyverse)
IBSlogo <- tribble(
~Row, ~Col, ~Fill, ~Text,
3, 1, "white", "I",
3, 2, "#7fb8ff", "",
3, 3, "#0170fe", "",
2, 1, "#0170fe", "",
2, 2, "white", "B",
2, 3, "#7fb8ff", "",
1, 1, "#7fb8ff", "",
1, 2, "#0170fe", "",
1, 3, "white", "S")
getIBSlogowFrame <- function(frame, shuffle=TRUE) {
if(shuffle) {
IBSlogo %>%
mutate(Fill=sample(Fill),
Frame=frame)
} else {
IBSlogo %>%
mutate(Frame=frame)
}
}
set.seed(1)
df <- map2(1:10, c(rep(TRUE, 7), rep(FALSE, 3)),
getIBSlogowFrame) %>%
plyr::ldply()
anim <- ggplot(df, aes(Col, Row)) +
geom_tile(aes(fill=I(Fill)), color="black",
width=0.98, height=0.98) +
geom_text(aes(label=Text), size=20,
family = "Times New Roman",
fontface="bold") +
theme_void() +
coord_equal() +
transition_states(Frame,
transition_length=1,
state_length=1)
animate(anim, width=300, height=300)
anim_save("IBSlogo.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.