I want to create a timeline like this one using R
's timevis
package.
I know how to build a group as they do in the demo:
library(timevis)
dataGroups <- data.frame(
id = 1:11,
content = c(
"Open",
"Open",
"Open",
"Open",
"Half price entry",
"Staff meeting",
"Open",
"Adults only",
"Open",
"Hot tub closes",
"Siesta"
),
start = c(
"2016-05-01 07:30:00",
"2016-05-01 14:00:00",
"2016-05-01 06:00:00",
"2016-05-01 14:00:00",
"2016-05-01 08:00:00",
"2016-05-01 08:00:00",
"2016-05-01 08:30:00",
"2016-05-01 14:00:00",
"2016-05-01 16:00:00",
"2016-05-01 19:30:00",
"2016-05-01 12:00:00"
),
end = c(
"2016-05-01 12:00:00",
"2016-05-01 20:00:00",
"2016-05-01 12:00:00",
"2016-05-01 22:00:00",
"2016-05-01 10:00:00",
"2016-05-01 08:30:00",
"2016-05-01 12:00:00",
"2016-05-01 16:00:00",
"2016-05-01 20:00:00",
NA,
"2016-05-01 14:00:00"
),
group = c(rep("lib", 2), rep("gym", 3), rep("pool", 5), NA),
subgroup = c("A", "A", "B", "C", "C", "D", "D", "E", "E", "E", NA),
type = c(rep("range", 9), "point", "background")
)
groups <- data.frame(id = c("lib", "gym", "pool"),
content = c("Library", "Gym", "Pool"))
timevis(
data = dataGroups,
groups = groups,
options = list(editable = TRUE, stack = FALSE)
)
I don't know how to include the subgroups in the final timeline.
I believe it might be possible using setGroups
or including some options using htmlwidgets::JS()
. I was trying the examples in the docs using the second option and it doesn't seem to work:
timevis(
data.frame(
id = 1,
content = "double click anywhere<br>in the timeline<br>to add an item",
start = "2016-01-01"
),
options = list(
editable = TRUE,
onAdd = htmlwidgets::JS(
'function(item, callback) {
item.content = "Hello!<br/>" + item.content;
timevis 19
callback(item);
}'
)
)
)
Any example of a timeline including subgroups would be appreciated.
In case this feature can't be used in R
is there an alternative available?