【发布时间】:2016-06-17 06:31:41
【问题描述】:
当使用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 = ...)) 参数?我可以想象更改数据的时区会很糟糕的情况,特别是在处理夏令时事件时。
【问题讨论】:
-
您是否碰巧找到了解决方案?