问题描述
我有以下数据框,其中“库存”列中有两个不同的条目:
瞥见(df_final_time_series)
Rows: 396
Columns: 3
$ date <date> 2004-01-01,2004-02-01,2004-03-01,2004-04-01,200...
$ stock <chr> "vtv","vtv","vt...
$ price <dbl> 31.70592,32.52995,31.80250,31.43529,31.66834,32...
我用以下代码创建了时间序列图:
df_final_time_series %>%
ggplot(aes(x=stock,y=price)) +
geom_line(aes(color = stock),size = 2) +
geom_segment(aes(xend = stock,yend = price)) +
geom_label(aes(label = price))+
labs(title = "",subtitle = "Time-Series Performances of VTV and VUG",caption = "Source: Yahoo Finance") +
gganimate::transition_reveal(as.Date(date)) +
ggthemes::theme_fivethirtyeight()
此代码运行正常。我现在正在尝试使用Year:YYYY来复制图表,标题随着数据点的变化而变化。
我尝试实现transition_time(year)和其他几种变体,但是遇到错误 有50个或更多警告(使用warnings()查看前50个) 警告消息:
1:无法获得绘图表的尺寸。绘图区域可能不固定 2:找不到对象“年份” 3:找不到对象“年份” ... 50:找不到对象“年份”
df_final_time_series %>%
ggplot(aes(x=stock,yend = price)) +
geom_label(aes(label = price))+
transition_time(year)+
labs(title = "Year: {year}",caption = "Source: Yahoo Finance") +
gganimate::transition_reveal(as.Date(date)) +
ggthemes::theme_fivethirtyeight()
解决方法
您是否尝试过{frame_time},而不是{year}?这就是gganimate帮助页面显示的内容。参见gganimate.com。