Created
January 5, 2019 15:24
-
-
Save a-lexwein/74723979d3f3f198137b0f14bf265eb9 to your computer and use it in GitHub Desktop.
animated pie chart with gganimate
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(dplyr) | |
library(ggplot2) | |
library(gganimate) | |
open <- c(.16, 1 - .16) | |
closed <- c(.02, .98) | |
colors <- c("#EDD63F", "#4C4C4C") # yellow and dark gray | |
data <- tibble( | |
position = c(open, closed), | |
frame = c(1,1,2,2), | |
body_part = rep(c("mouth", "head"), 2) | |
) | |
gg <- data %>% | |
ggplot(aes(x = 1, y = position, fill = body_part)) + | |
geom_col(width = 1) + | |
coord_polar(theta = "y", start = 1.2) + | |
annotate("text", x = 1.2, y = .93, label = "O", size = 10) + | |
scale_fill_manual(values = colors) + | |
theme_void() + | |
transition_states(frame, 5, 1) | |
anim_save("ggpietalk1", animate(gg, nframes = 20, fps = 20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment