在绘制季节ggplot2时添加日期

时间:2017-02-23 09:46:00

标签: r

我想绘制几年的时间序列,但仅限于夏季。我的问题是当我尝试将日期添加到X轴时。让我们说我的数据具有以下结构:

      day       date    value      Region variable Data
       1    1998-06-01 72.69090      IP       O3  OBS
       2    1998-06-02 86.09606      IP       O3  OBS
       3    1998-06-03 93.50078      IP       O3  OBS
       4    1998-06-04 96.41037      IP       O3  OBS
        .........................................
      1194  2010-08-29  97.36273     IP       O3  OBS
      1195  2010-08-30 100.09310     IP       O3  OBS
      1196  2010-08-31  98.55973     IP       O3  OBS

我将dat $ date转换为Date

我做了我的情节:

m <- ggplot(dat, aes(day, value)) + 
       geom_line(aes(color=Data),size=0.3,na.rm=TRUE)

在这种情况下,我的情节看起来像: enter image description here

如果我使用dat $ date代替:

m <- ggplot(dat, aes(date, value)) +
       geom_line(aes(color=Data),size=0.3,na.rm=TRUE) +
       scale_x_date(date_breaks ="1 year",labels = date_format("%Y"))

然后我会: enter image description here

那么,我如何添加日期,但获得类似于第一个的情节? 我想这是因为我只画了3个月,但我想连续拍摄。有什么想法吗?

提前致谢

0 个答案:

没有答案