Suppose we have POSIXct values x.
library(chron)
# input
y <- 1:5
x <- as.POSIXct(c("2004-09-08 13:50:00", "2004-09-08 14:00:00", "2004-09-08 14:10:00",
"2004-09-08 14:20:00", "2004-09-08 14:30:00"))
1) Convert them to a chron class "times"and write:
ti <- times(format(x, "%H:%M:%S"))
plot(y ~ ti)
2) , or you can do it using the zoo:
library(zoo)
z <- zoo(y, x)
zz <- z
time(zz) <- times(format(time(zz), "%H:%M:%S"))
plot(zz)
2a) ggplot2 autoplot.zoo :
library(ggplot2)
autoplot(zz) + scale_x_chron(format = "%H:%M")
2b) , . zoo/ggplot2/, chron, X:
library(scales)
autoplot(z) + scale_x_datetime(breaks = "10 min", labels = date_format("%H:%M"))