daattali / timevis

📅 Create interactive timeline visualizations in R
http://daattali.com/shiny/timevis-demo/
Other
653 stars 157 forks source link

Stacking Weird #14

Closed sco-lo-digital closed 7 years ago

sco-lo-digital commented 7 years ago

Hi I have a problem that may well be of my own doing, but I don't see it.

Instead of plotting the observations sequentially, they are being stacked after the 9th one.

I have the following code;

` library(timevis) library(lubridate) indexdate <- "2014-01-01" %>% as.Date()

twelveMo <- data.frame( content = c(paste0(rep("predictor"),1:12), paste0(rep("event"),1:12)), start = c(seq.Date(indexdate, by= "month", length.out = 12), seq.Date(indexdate %m+% months(12), by= "month", length.out = 12) ), end = c(seq.Date(indexdate %m+% months(12), by= "month", length.out = 12), seq.Date(indexdate %m+% months(15), by= "month", length.out = 12)), group = c(rep(1:12), rep(1:12)))

twelveMo

timevis(twelveMo, groups = data.frame(id = 1:12, content = c(paste0(rep("G_"),1:12))))`

weirdstacking

daattali commented 7 years ago

I don't know what the issue here is. That timevis image looks fine to me, you didn't say what you expected to see that isn't seen.

Also, I highly suggest you use a variable instead of hardcoding the number 12 so many times. I notice that in one of the places you use the number 15, I'm not sure if that's intentional or not.

sco-lo-digital commented 7 years ago

Let me try to rephrase - why is the predictor_10 box put on top instead of underneath predictor_9? This is in Group 10 which should come after Group 9. Am I missing something?

15s and 12s are intentional. Thanks.

daattali commented 7 years ago

Ah, that behaviour is completely up to the underlying timeline javascript library. Looking at the documentation (which is linked from timevis), it looks like there's a a configuration option called groupOrder:

Order the groups by a field name or custom sort function. By default, groups are ordered by a property order (if set). If no order properties are provided, the order will be undetermined.

This implied that you should be able to add a order variable to your groups data frame if you want to enforce a particular order. My guess is that something like groups = data.frame(id = 1:12, content = c(paste0(rep("G_"),1:12)), order = 1:12) would work

sco-lo-digital commented 7 years ago

Perfect! Thanks so much!