问题描述
我希望在 R 中的一个相当简单的时间序列图上设置 x 轴限制。 我的绘图产生的限制比我的时区 提前 6 小时(在下面的示例中,绘图将在 14:00:00 开始和结束)。 我目前在“美国/丹佛”。
我的数据之前已绘制,因此所有内容都向后移动了 6 小时 但我能够在 x 轴上正确对齐,但现在 x 轴的边界/限制仍然存在一个问题。
date_format <- function(format = "%b %d - %H:%M") {function(x) format(x,format)}
lims <- as.POSIXct(strptime(c("2021-05-04 08:00:00","2021-05-08 08:00:00"),format = "%Y-%m-%d %H:%M"))
combo_ch1short <- ggplot(data = data_combo_ch1short,aes(x = DateTime,y = Z.kOhm,color = probe.pair.name)) +
scale_x_datetime(labels = date_format(),limits = lims,date_breaks = "12 hours") + ...
抱歉,这还很陌生。非常感谢任何帮助!
编辑:
data_combo_ch1short:
Time probe.pair.name DateTime Z.kOhm
1617890878 ch_1_ch_2 2021-04-12 17:52:32 5228.69
1617890878 ch_1_ch_3 2021-04-12 17:52:32 5031.88
1618251752 ch_1_ch_2 2021-04-12 18:22:32 4089.37
1618251752 ch_1_ch_3 2021-04-12 18:22:32 4231.90
...
解决方法
您可以通过在 lims
参数中指定时区来在任何时区创建 tz
。
lims <- as.POSIXct(c("2021-05-04 08:00:00","2021-05-08 08:00:00"),tz = 'US/Mountain')