wah*_*ulu 3 timezone datetime r ggplot2
我似乎无法找到有关ggplot2 0.9.0文档,0.9.0过渡指南或搜索的信息.
我想在早期版本中你要添加tz
参数scale_x_datetime
.我已经尝试将tz
论点放在不同的地方,scale_x_datetime
但不断出错.见下文.
我的日期时间数据POSIXct
采用GMT时区格式.当我绘制它时,轴刻度和中断显示我的当地时区(EST).我希望轴上的午夜在GMT时区午夜.在ggplot2 0.9.0中执行此操作的正确方法是什么?
attributes(data$date)
# $class
# [1] "POSIXct" "POSIXt"
# $tzone
# [1] "GMT"
ggplot(data, aes(x = date)) +
geom_line(aes(y = count)) +
scale_x_datetime(breaks = date_breaks("1 day"),
labels = date_format("%d", tz = "UTC"))
# Error in date_format("%d", tz = "UTC") : unused argument(s) (tz = "UTC")
ggplot(data, aes(x = date)) +
geom_line(aes(y = count)) +
scale_x_datetime(breaks = date_breaks("1 day", tz = "UTC"),
labels = date_format("%d"))
# Error in date_breaks("1 day", tz = "UTC") :
# unused argument(s) (tz = "UTC")
ggplot(data, aes(x = date)) +
geom_line(aes(y = count)) +
scale_x_datetime(breaks = date_breaks("1 day"),
labels = date_format("%d"),
tz = "UTC")
# Error in continuous_scale(aesthetics, "datetime", identity, breaks = breaks, :
# unused argument(s) (tz = "UTC")
Run Code Online (Sandbox Code Playgroud)
@joran在正确的轨道上,但是其他参数不能通过格式化函数传递,因此需要将它们传递给生成器函数:
date_format_tz <- function(format = "%Y-%m-%d", tz = "UTC") {
function(x) format(x, format, tz=tz)
}
Run Code Online (Sandbox Code Playgroud)
然后可以称为:
scale_x_datetime(breaks = date_breaks("1 day"),
labels = date_format_tz("%d", tz="UTC"))
Run Code Online (Sandbox Code Playgroud)
由于比例为2.2(〜jul 2012),因此可以将tz
参数传递给time_trans
。
例如,它以UTC格式格式化时间戳,并且不需要其他编码:
+scale_x_continuous(trans = time_trans(tz = "UTC"))
Run Code Online (Sandbox Code Playgroud)