r - R gganimate transition_time() 函数
问题描述
我有以下数据框,其中“库存”列中有两个不同的条目:
一瞥(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", "vtv", "vtv", "vtv", "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, y=price)) +
geom_line(aes(color = stock), size = 2) +
geom_segment(aes(xend = stock, yend = price)) +
geom_label(aes(label = price))+
transition_time(year)+
labs(title = "Year: {year}",
subtitle = "Time-Series Performances of VTV and VUG",
caption = "Source: Yahoo Finance") +
gganimate::transition_reveal(as.Date(date)) +
ggthemes::theme_fivethirtyeight()
解决方案
你试过 {frame_time} 而不是 {year}?这就是 gganimate 帮助页面显示的内容。请参阅 gganimate.com。
推荐阅读
- c# - 剑道网格的内联剑道下拉值不绑定
- android - android jetpack compose中的“remember”和“mutableState”有什么区别?
- image-processing - 如何检查 TIFF 文件是否真正具有 16 位深度
- javascript - VueJS - 父对象受子对象中此对象的深层副本更改的影响
- r - 如何使用 DoParallel 通过 R 中的条件索引来并行化矩阵切片?
- php - 在 woocommerce_package_rates 挂钩中的运输方式标签后添加文本
- javascript - Res.buffer 在获取数据时不是函数错误
- python - 使用主列查找两个 CSV 文件之间的差异
- python - 是否可以从 Django 相关字段中的类插值创建蛇案例`related_name`?
- r - 有没有人可以帮助 R Error in while (x <= 100) { : 参数长度为零