0

I would like to use tweenr with a date format variable for the timepoints.

However, tweenr::tween_elements throws an error, that I cannot decipher:

> Error in `/.difftime`(diff(timerange), nframes) : 
  second argument of / cannot be a "difftime" object

Am I using the wrong tweenr function? This is most probably some expected behaviour, but I can't get my head round this.

Reproducible Example:

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')
chamaoskurumi
  • 2,271
  • 2
  • 23
  • 30

1 Answers1

0

Working with dates in tweenR can be sometimes tricky.

It works very well if you specify the date as an integer:

> 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

Code

data_tween <- tween_elements(data, "time", "group", "ease", nframes = 100)

Data

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"
)
Roman
  • 4,744
  • 2
  • 16
  • 58