问题描述
在这里,我将继续使用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 (将#修改为@)