当使用lattice
绘制每小时时间戳的值时,我发现在图表的x轴标签中有一个恼人的时区从UTC转移到当地时间。虽然此示例使用lubridate
,但直接使用POSIXct
时会出现问题。例如:
library(lattice)
library(lubridate)
foo <- data.frame(t = seq(ymd_hms("2015-01-01 00:00:00"),
ymd_hms("2015-01-02 00:00:00"),
by = "hour"),
y = 1:25)
head(foo)
xyplot(y~t, foo) # time axis is behind by 5 hours (EST = UTC-5)
一种解决方案是明确指定时区:
tz(foo$t) <- "" # or tz(foo$t) <- "EST"
head(foo)
xyplot(y~t, foo) # time axis now agrees
是否有其他方法可以让lattice
直接在UTC中绘制而不修改数据的时区?也许使用scales = list(x = list(format = ...))
参数?我可以想象改变数据时区的情况,特别是在处理夏令时事件时。