更改时间序列中绘制的初始时间 - ggplot2

时间:2014-08-19 23:04:24

标签: r ggplot2

我有一个由每小时温度样本组成的数据集。采样从16:00开始,我想从16:00开始每隔6小时标记一次x轴。在我的尝试中,我设法做到以下几点:

我无法弄清楚的是为什么剧情将在16:07开始。 有没有办法将第一次设定为16:00?

我的情节:

library(ggplot2); library(scales)
grafico <- ggplot(data=data, aes(x = dt, y = temp))
grafico <- grafico + geom_line(size=0.3, color="red3")
grafico <- grafico + scale_x_datetime( breaks = date_breaks("6 hour"), labels = date_format("%H:%m"), minor_breaks = date_breaks("1 hour"), expand = c(0, 0))
grafico <- grafico + scale_y_continuous(expand=c(0,0))

我的数据:

dt  temp
2014-07-24 16:00:00 10.467
2014-07-24 17:00:00 10.638
2014-07-24 18:00:00 7.720
2014-07-24 19:00:00 2.797
2014-07-24 20:00:00 1.886
2014-07-24 21:00:00 0.412
2014-07-24 22:00:00 0.246
2014-07-24 23:00:00 0.632
2014-07-25 00:00:00 -0.676
2014-07-25 01:00:00 -0.676
2014-07-25 02:00:00 -1.384
2014-07-25 03:00:00 -1.213
2014-07-25 04:00:00 -3.124
2014-07-25 05:00:00 -1.327
2014-07-25 06:00:00 -1.929
2014-07-25 07:00:00 -1.157
2014-07-25 08:00:00 -1.242
2014-07-25 09:00:00 2.850

structure(list(dt = structure(1:18, .Label = c("2014-07-24 16:00:00", 
"2014-07-24 17:00:00", "2014-07-24 18:00:00", "2014-07-24 19:00:00", 
"2014-07-24 20:00:00", "2014-07-24 21:00:00", "2014-07-24 22:00:00", 
"2014-07-24 23:00:00", "2014-07-25 00:00:00", "2014-07-25 01:00:00", 
"2014-07-25 02:00:00", "2014-07-25 03:00:00", "2014-07-25 04:00:00", 
"2014-07-25 05:00:00", "2014-07-25 06:00:00", "2014-07-25 07:00:00", 
"2014-07-25 08:00:00", "2014-07-25 09:00:00"), class = "factor"), 
temp = c(10.467, 10.638, 7.72, 2.797, 1.886, 0.412, 0.246, 
0.632, -0.676, -0.676, -1.384, -1.213, -3.124, -1.327, -1.929, 
-1.157, -1.242, 2.85)), .Names = c("dt", "temp"), class = "data.frame", row.names = c(NA, -18L))

我对R.很新。 欢迎使用代码中的任何建议。

0 个答案:

没有答案