ggplot 0.9.0中的scale_datetime()的适当时区参数语法是什么? [英] What is the appropriate timezone argument syntax for scale_datetime() in ggplot 0.9.0

查看:123
本文介绍了ggplot 0.9.0中的scale_datetime()的适当时区参数语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到有关ggplot2的信息 0.9.0文档, 0.9.0转换指南或搜索。

I can't seem to find the information on the ggplot2 0.9.0 documentation, 0.9.0 transition guide, or search.

我想在早期版本中,您将添加 tz 参数 scale_x_datetime 。我已经尝试将 tz 参数放在 scale_x_datetime 中的不同位置,但仍然收到错误。

I guess in earlier versions you'd add the tz argument to scale_x_datetime. I've tried placing the tz argument in different places within scale_x_datetime but keep getting errors. See below.

我的日期时间数据位于GMT时区的 POSIXct 格式。当我绘制它,轴刻度和断点显示我的本地时区(EST)。我希望午夜在GMT时区的午夜是午夜。在ggplot2 0.9.0中有什么正确的方法?

My datetime data is in POSIXct format with GMT timezone. When I plot it, the axis ticks and breaks are showing my local timezone (EST). I'd like midnight on the axis to be midnight in GMT timezone. What is the right way to do this in 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")


推荐答案

由于 scale 2.2 (〜jul 2012)可以将 tz 参数传递给 time_trans

Since scales 2.2 (~jul 2012) it is possible to pass tz argument to time_trans.

例如,它用UTC格式化时间戳,不需要额外的编码:

For instance, that formats timestamps in UTC and requires no additional coding:

+scale_x_continuous(trans = time_trans(tz = "UTC"))

这篇关于ggplot 0.9.0中的scale_datetime()的适当时区参数语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆