0

我想tweenrdate格式变量一起使用timepoints.

但是,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')
4

1 回答 1

0

处理日期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"
)
于 2018-10-16T10:16:30.363 回答