GGanimateR:创建动画与一系列图像

问题描述

在这里,我将继续使用R库'gganimate'创建动画,其中包含我模拟的序列数据的动画:

https://www.datanovia.com/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/

(滚动到中间)

首先,我创建了一些数据

#create data
date_decision_made = seq(as.Date("2014/1/1"),as.Date("2016/1/1"),by="day")

date_decision_made <- format(as.Date(date_decision_made),"%Y/%m/%d")

property_damages_in_dollars <- rnorm(731,100,10)

car_damages_in_dollars <- rnorm(731,105,8)

other_damages_in_dollars <- rnorm(731,104,9)

final_dataset <- cbind(date_decision_made,property_damages_in_dollars,car_damages_in_dollars,other_damages_in_dollars)

final_dataset <- as.data.frame(final_dataset)

然后,我将数据转换为长格式并更改了日期类型:

library(reshape2)
library(ggplot2)

dd = melt(final_dataset,id=c("date_decision_made"))
dd$date_decision_made <- as.Date(as.character(dd$date_decision_made),'%Y/%m/%d')

然后,我尝试制作动画

library(gganimate)

p <- ggplot(
    dd,aes(date_decision_made,value,group = variable,color = factor(variable))
) +
    geom_line() +
    scale_color_viridis_d() +
    labs(x = "date",y = "dollars") +
    theme(legend.position = "top")

p + 
  geom_point() +
  transition_reveal(date_decision_made)

但是,这产生了100个不同的图像而不是动画。有可能解决这个问题吗?还是我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...