我想将tweenr
与timepoints
的date
格式变量一起使用。
但是,tweenr::tween_elements
抛出一个我无法破译的错误:
> Error in `/.difftime`(diff(timerange), nframes) :
second argument of / cannot be a "difftime" object
我是否使用了错误的tweenr
功能?这很可能是一些预期的行为,但我无法理解这一点。
可重现的示例:
if (!require(devtools)) {
install.packages("devtools")
}
devtools::install_github("thomasp85/tweenr")
library(ggplot2)
library(gganimate)
library(ggforce)
library(tweenr)
data <- data.frame(
time = rep(seq(as.Date("2000-01-01"),
as.Date("2009-01-01"),
"year"),
2),
x = c(1:10,20:11),
y = c(20:11,1:10),
group = c(rep(1,10), rep(2,10)),
ease = rep('cubic-in-out', 20)
)
data <- tween_elements(data, 'time', 'group', 'ease')
在tweenR
中使用日期有时可能很棘手。
如果您将日期指定为整数,它的效果非常好:
> head(data_tween)
time x y .frame .group
1 2000.000 1.000000 20.000000 0 1
102 2000.000 20.000000 1.000000 0 2
2 2000.003 1.003005 19.996995 1 1
103 2000.003 19.996995 1.003005 1 2
3 2000.024 1.024042 19.975958 2 1
104 2000.024 19.975958 1.024042 2 2
法典
data_tween <- tween_elements(data, "time", "group", "ease", nframes = 100)
数据
data <- data.frame(
time = rep(seq(2000, 2009), 2),
x = c(1:10, 20:11),
y = c(20:11, 1:10),
group = c(rep(1, 10), rep(2, 10)),
ease = "cubic-in-out"
)