【问题标题】:ggseasonplot for hourly data with weekly seasonality equivalentggseasonplot 用于每周季节性等效的每小时数据
【发布时间】:2019-05-11 12:33:21
【问题描述】:

我有一个分辨率为一小时的时间序列,它显示每周的季节性。我正在寻找适用于每周季节性的 ggplot2 包中的函数 ggseasonplot 的等效项。

我在网上查了一下,没有找到类似的功能,除了seasonplot,和ggseasonplot一样,但没那么花哨。

data<-read.csv("series.csv") 
hours <- seq(ISOdatetime(2016,4,18,0,0,0), ISOdatetime(2016,5,22,23,0,0), by=(60*60))
time_series<- xts::xts(data[123118:123957,2],hours)
time_series168 <- ts(data,frequency = 168)

ggseasonplot(time_series168,continuous = TRUE)

我想在情节上用几周而不是一年。在情节上,一周中的每个小时都是一个季节,我希望“季节”是几天。

我的数据样本:

Datetime            series
2016-04-18 00:00:00 4124
2016-04-18 01:00:00 3932
2016-04-18 02:00:00 3823
2016-04-18 03:00:00 3830
2016-04-18 04:00:00 3797
2016-04-18 05:00:00 3935

【问题讨论】:

    标签: r


    【解决方案1】:

    我想出了一个解决方案,所以我发布它以防其他人正在寻找这个:

    plot(1:168,time_series168[1:168],type="l",xaxt = "n",col=rgb(0,0.2,1),xlab="Days of week",ylab="Time series",main="Evolution of time series over the weeks",lwd=1.5)
    
    for(i in 1:4){
       color<-rgb(0.25*i,0.2,1-0.2*i)
       left<-168*i+1
       right<-168*(i+1)
       lines(1:168,time_series168[left:right],type="l",xaxt = "n", col=color, lwd=1.5)
    } 
    
    axis(1, at=c(24,48,72,96,120,144,168)-12, labels=c("Mon","Tue","Wed","Thu","Fri","Sat","Sun"))
    legend("topright",bty="n",legend=c("into the past","into the future"), col=c(rgb(0,0.2,1), rgb(1,0.2,0.2)), lty=1,lwd=2)
    

    通过设置xaxt = "n" 轴是无标签的,那么可以在axis 中用labels 标记它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      相关资源
      最近更新 更多