【问题标题】:Animated plot with polar coordinates带有极坐标的动画图
【发布时间】:2018-05-31 03:19:36
【问题描述】:

我正在尝试使用 ggplot2 创建一个动画饼图。

我的数据有点复杂,但这里有一个简化的例子:

ex = data.frame(cat=c("cat1","cat2","cat1","cat2","cat1","cat2"), f = c(70,30,60,40,50,50), t=c(1,1,2,2,3,3))
ex$t = factor(ex$t)

p = ggplot(ex, aes(x="", y=f, fill=cat, frame=t))+
  geom_bar(width = 1, stat = "identity") +
  coord_polar("y", start=0) 

gganimate(p, "ex.gif", interval=1)

如果我显示 p,似乎没问题:simple png

但是 gif 不行:gif

知道如何解决这个错误吗?

【问题讨论】:

  • 看看this 的帖子。希望对您有所帮助。

标签: r ggplot2 gganimate


【解决方案1】:

生成的.gif 在我看来是正确的。每个帧都是用单独的数据生成的。也许您正在寻找逐渐生成的饼图。您应该使用cumulative = TRUE 来构建累积帧数。

代码应改为:

p = ggplot(ex, aes(x="", y=f, fill=cat, frame=t, cumulative = TRUE))+
  geom_bar(width = 1, stat = "identity") +
  coord_polar("y", start=0) 

【讨论】:

  • png 图像应该是 gif 帧之一。馅饼应该是满的,因为数字加起来都是 100。不是吗?
  • 完整的饼图显示 300。每个观察值加起来为 300。如果累积为 TRUE,则饼图将在第 3 帧填满。
猜你喜欢
  • 1970-01-01
  • 2013-06-18
  • 1970-01-01
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 2016-08-17
  • 2018-05-08
  • 1970-01-01
相关资源
最近更新 更多