scale_datetime shifts x axis [duplicate]

拜拜、爱过 提交于 2019-12-06 09:52:13

It's a time zone issue. date_format sets the time zone to "UTC" by default and internally calls format.POSIXct which calls as.POSIXlt internally. There this happens:

as.POSIXlt(start, "UTC")
#[1] "2014-06-30 22:00:00 UTC"

Voilà, a different month.

You can avoid this by not changing the time zone:

p + scale_x_datetime(breaks=date_breaks("1 month"), 
                     labels=date_format("%b-%y", tz = Sys.timezone(location = TRUE)))

If you explicitly defined a time zone (you should) when creating the POSIXct variable, you should pass this time zone here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!