Search code examples
rvistime

R Timeline Without Dates


I'm trying to make a timeline like you'd make with any of the timevis, vistime, or timeline R packages, but I'm only interested in times and not dates. I don't mind putting a placeholder date in there, but it seems that all of these packages require the start and end times to include dates and include the date in the timeline.

I've been searching for ways to either not include dates in a timeline or only print the time but not the date in any of these package, but haven't been able to find anything. Does anyone have any ideas?


Solution

  • All of those packages use as.POSIXct under the hood, which requires objects to be Date objects and doesn't work with times only. So, if your data is about only one day, you can add the date on the clock times (using paste) and e.g. vistime will display only the time (ok, a date almost completely hidden in the corner):

    dat <- data.frame(event = 1:2,
                        start = c("14:00", "16:00"),
                        end = c("15:30", "17:00"))
    
    # add a Date
    dat[,c("start", "end")] <- sapply(dat[,c("start", "end")], function(x) paste(Sys.Date(), x))
    
    vistime(dat)
    

    enter image description here

    I use vistime version 0.7.0.9000 which can be obtained by executing devtools::install_github("shosaco/vistime").