Skip to content

Instantly share code, notes, and snippets.

@amoeba
Created January 3, 2015 02:17
Show Gist options
  • Select an option

  • Save amoeba/bf1144cae3466be56ba9 to your computer and use it in GitHub Desktop.

Select an option

Save amoeba/bf1144cae3466be56ba9 to your computer and use it in GitHub Desktop.
Pyramid Pie Chart Animation in ggplot2
library("ggplot2")
library("animation")
saveGIF({
for(shadyside in 1:39)
{
sides <- c("Sky", "Sunny side of pyramid", "Shady side of pyramid")
amounts <- c(150, 40 - shadyside, shadyside)
mydf <- data.frame(values=ordered(rep(sides, amounts), levels = sides))
p <- ggplot(mydf, aes(x = factor(1), fill=factor(values))) +
geom_bar(width = 1) +
coord_polar(theta = "y", start = 3.8, direction = -1) +
scale_fill_manual(values = c("#0095d9", "#f5e837", "#c4b633")) +
theme(axis.line = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position = c(1, .9),
legend.title = element_blank(),
panel.background = element_blank())
print(p)
}
}, interval = 1/30, ani.width = 550, ani.height=450)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment