Skip to content

Instantly share code, notes, and snippets.

@a-lexwein
Created January 5, 2019 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-lexwein/74723979d3f3f198137b0f14bf265eb9 to your computer and use it in GitHub Desktop.
Save a-lexwein/74723979d3f3f198137b0f14bf265eb9 to your computer and use it in GitHub Desktop.
animated pie chart with gganimate
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