我正在尝试使用ggplot2和gganimate在R中制作一些绘图动画。
我阅读了一些教程并成功地对gapminder数据进行了动画处理。
然而,当我尝试为我的数据集设置动画时,我遇到了问题。首先,我创建了plot,并尝试像这样设置它的动画:
animate_data_1 <- ggplot(data_1,
aes(x = Month, y = rain, colour = factor(Year))) +
geom_line(stat = "identity") +
labs(x = "Month", y = "Rain") +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d()
animate_data_1
animate_data_1 + transition_time(Year) + labs(title = "Year: {frame_time}")上面的代码创建了动画情节,但它一次显示一年,然后更改为另一年。但是,我希望所有年份的值都会一次改变(从头到尾递增)。就像这个例子data gradually appear
所以,我做了这样的改变:
animate_data_1 +
geom_point(aes(group = seq_along(Month))) +
transition_reveal(Year) +
labs(title = "Year: {frame_time}")现在它显示了这个错误:
Error: Provided file does not exist In addition: There were 50 or more warnings (use warnings() to see the first 50)
有什么问题吗?如何解决这个问题?
我的数据:
tem Month Year rain
1 16.9760 1 1901 18.53560
2 19.9026 2 1901 16.25480
3 24.3158 3 1901 70.79810
4 28.1834 4 1901 66.16160
5 27.8892 5 1901 267.21500
6 28.8925 6 1901 341.04200
7 28.3327 7 1901 540.90700
8 27.9243 8 1901 493.21000
9 27.6057 9 1901 291.54900
10 27.0887 10 1901 199.17100
11 22.1671 11 1901 126.28500
12 18.5574 12 1901 1.69035
13 18.5455 1 1902 1.29152
14 20.1252 2 1902 0.14722
15 25.5508 3 1902 62.76860
16 26.5562 4 1902 229.58900
17 27.3165 5 1902 302.19700
18 28.2660 6 1902 528.77500
19 27.6247 7 1902 415.25700
20 28.1001 8 1902 435.16600
21 27.7271 9 1902 282.87200
22 26.0153 10 1902 76.65180发布于 2020-09-23 21:07:53
试一试,但时间框架不会来。然而,这段代码并没有给出逐步递增的情节,而是一年接着一年地给出了
animate_data_1 +
geom_point(aes(group = seq_along(Year)))+
transition_reveal(Year)发布于 2020-09-23 21:31:25
要获得每个月的移动,您需要定义一个新变量来组合年份和月份,如下所示,然后通过transition_time显示它。您可以更改fps值以提高或降低速度。
data_1$Yearm <- data_1$Year + data_1$Month*0.08
p <- animate_data_1 + transition_time(Yearm) +
labs(title = "Year: {frame_time}")
animate(p, fps=5)

https://stackoverflow.com/questions/64026163
复制相似问题