transition_time有效,但transition_reveal不起作用显示错误

问题描述

我正在尝试使用Rggplot2gganimate中的一些图制作动画。

我阅读了一些教程,并成功制作了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

解决方法

尝试一下,但是时间框架还没到。但是,这段代码并未给出逐渐增加的情节,而是一年又一年地给出

animate_data_1 + 
geom_point(aes(group = seq_along(Year)))+
transition_reveal(Year)
,

要获取每个月的动向,您需要定义一个新变量来组合年份和月份,如下所示,然后通过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)

output

相关问答

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