Matt
Matt

Reputation: 156

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?

Upvotes: 3

Views: 1027

Answers (2)

shosaco
shosaco

Reputation: 6165

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").

Upvotes: 2

zelite
zelite

Reputation: 1488

If you want to represent times without any date information, you should try out the package hms. It is part of the tidyverse collection and is described as:

A simple class for storing durations or time-of-day values and displaying them in the hh:mm:ss format.

Example use:

library(hms)
hms(56, 34, 12)
#> 12:34:56

Upvotes: 0

Related Questions