4

Utilizing the grouping feature in the excellent R timevis package is well documented and examples are provided in the help page of timevis::timevis().

The documentation also says that it is possible to define subgroups, which

"Groups all items within a group per subgroup, and positions them on the same height instead of stacking them on top of each other."

I am having trouble understanding how to use this feature. For example, in the example below, I would expect that "event 1" and "event 2" are defined as their own subgroups and hence they would be positioned on the same height. However, this is not the case.

timedata <- data.frame(
  id = 1:6, 
  start = Sys.Date() + c(1, - 10, 4, 20, -10, 10),
  end = c(rep(as.Date(NA), 4), Sys.Date(), Sys.Date() + 20),
  group = c(1,1,1,2,2,2),
  content = c("event 1", "event 2", "event 2", "event 1", "range 1",     "range 1"),
  subgroup = c("1.1", "1.2", "1.2", "2.1", "2.2", "2.2")
)

groups <- data.frame(id = c(1,2), content = c("g1", "g2"))
timevis::timevis(data =timedata, groups = groups)

The result of the example code. The definition of subgroups is unsuccesful

How to correctly utilize the subgroups feature?

1 Answers1

6

I'm working through the subgroup and subgroupOrder functions myself, and wanted to share a couple of tips. The code below should achieve overlaying the events on top of each other, as opposed to stacking them. Note the addition of stack = FALSE in the options list().

The other place to look is at the JS documentation: http://visjs.org/docs/timeline/

  timedata <- data.frame(
      id = 1:6, 
      start = Sys.Date() + c(1, - 10, 4, 20, -10, 10),
      end = c(rep(as.Date(NA), 4), Sys.Date(), Sys.Date() + 20),
      group = c(1,1,1,2,2,2),
      content = c("event 1", "event 2", "event 2", "event 1", "range 1",     "range 1"),
      subgroup = c("1.1", "1.2", "1.2", "2.1", "2.2", "2.2")
    )
    
    groups <- data.frame(id = c(1,2), content = c("g1", "g2"))
    timevis::timevis(data =timedata, groups = groups, options = list(stack = FALSE))

Produces this output, timvis groups

Not sure if that's exactly what you're trying to achieve, but just a response. Hope you've made some progress otherwise!

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
gmaly
  • 91
  • 4