n <- 100
y <- rnorm(n)
# labels as days
x <- seq(as.POSIXct("2024-05-01 11:23"), as.POSIXct("2024-05-07 14:50"), length.out=n)
xax <- time_axis(x)
grayplot(x, y, xat=NA, vlines=xax$x)
axis(side=1, at=xax$x, labels=xax$label, mgp=c(2.1, 0.5, 0), tick=FALSE)
# labels as HH:MM
x <- seq(as.POSIXct("2024-05-01 11:23"), as.POSIXct("2024-05-01 14:50"), length.out=n)
xax <- time_axis(x)
grayplot(x, y, xat=NA, vlines=xax$x)
axis(side=1, at=xax$x, labels=xax$label, mgp=c(2.1, 0.5, 0), tick=FALSE)
# labels as seconds
x <- seq(as.POSIXct("2024-05-01 11:23:05.3"), as.POSIXct("2024-05-01 11:23:55.7"), length.out=n)
xax <- time_axis(x)
grayplot(x, y, xat=NA, vlines=xax$x)
axis(side=1, at=xax$x, labels=xax$label, mgp=c(2.1, 0.5, 0), tick=FALSE)
# custom time format
xax <- time_axis(x, format="%H:%M:%S")
grayplot(x, y, xat=NA, vlines=xax$x)
axis(side=1, at=xax$x, labels=xax$label, mgp=c(2.1, 0.5, 0), tick=FALSE)
Run the code above in your browser using DataLab