gganimate:将堆积的条形图转换为饼图

时间:2020-11-04 19:16:27

标签: r ggplot2 gganimate

我想制作一个堆叠的条形图的gif图像,该条形图会慢慢转变成饼图。使用ggplot和gganimate可以做到这一点吗?我知道如何静态执行此操作,但是是否可以让gganimate创建额外的帧以在两者之间进行平滑过渡?

library(ggplot2)
library(gganimate)

df <- data.frame(
  group = rep(c("Male", "Female", "Child"),2),
  value = c(25, 25, 50, 30,50,20),
  frame = c("Jan","Jan","Jan","Feb","Feb","Feb")
)

# Barplot
bp <- ggplot(df, aes(x="", y=value, fill=group))+
  geom_bar(width = 1, stat = "identity") +
  ggtitle('Percent of population by age group: {closest_state}') + 
  
  transition_states(frame)


pie <- bp + coord_polar("y", start=0) 

bp
pie

0 个答案:

没有答案