Bry*_*yan 1 format r time-series lattice
I often deal with time series data with timescales of years, months, days, minutes, and seconds. When plotting, it would be convenient to easily change the way the time series axes are displayed, along the lines of a strptime command.
library(lattice)
t_ini = "2013-01-01"
ts = as.POSIXct(t_ini)+seq(0,60*60*24,60*60)
y = runif(length(ts))
# default plot with time series axis in M D h:m
xyplot(y~ts)
# this attempt at using format to display only hours on the x-axis does not work:
xyplot(y~ts, scales=list(x=list(labels=format("%H"))))
Run Code Online (Sandbox Code Playgroud)
There seems to be a format command in the scales argument, but I can't seem to get the hang of it. Any ideas? Thanks!
Bryan
xyplot(y~ts, scales=list(x=list(at= as.numeric(ts),
labels=format(ts, "%H"))))
Run Code Online (Sandbox Code Playgroud)
要每六个小时制作一次刻度,你只需使用seq.POSIXt:
xyplot(y~ts, scales=list(
x=list(at= seq(as.POSIXct(t_ini), by="6 hour", length=5),
labels=format(seq(as.POSIXct(t_ini), by="6 hour", length=5),
"%H hrs"))
)
Run Code Online (Sandbox Code Playgroud)