消除格子xyplot中的时间戳时区偏移

时间:2016-03-03 18:50:43

标签: r timestamp lattice

当使用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 = ...))参数?我可以想象改变数据时区的情况,特别是在处理夏令时事件时。

0 个答案:

没有答案