【问题标题】:Add date for time series in dygraphs在 dygraphs 中添加时间序列的日期
【发布时间】:2015-03-06 16:40:54
【问题描述】:

我有以下数据,我试图用 R 中的 dygraphs 绘制:

ts.rmean ts.rmax
0001-01-01  3.163478    5.86
0002-01-01  3.095909    4.67
0003-01-01  3.112000    6.01
0004-01-01  2.922800    5.44
0005-01-01  2.981154    5.21
0006-01-01  3.089167    5.26
0007-01-01  3.168000    6.28
0008-01-01  3.040400    5.00
0009-01-01  2.809130    6.04
0010-01-01  3.002174    4.64
0011-01-01  3.002000    4.93
0012-01-01  3.081250    5.28
0013-01-01  2.687083    4.62

每条线代表 ts.rmeants.rmax 在 1 月 1 日至 12 月 31 日之间的每日值。由于我没有指定日期,所以绘图的 x 轴显示从 1 到 366 的每一行的索引。可以修改数据,使 x 轴显示 Month-Day?

【问题讨论】:

    标签: r xts dygraphs


    【解决方案1】:

    你可以这样做:

    library(dygraphs)
    library(xts)
    
    #convert the rownames of your data frame to a year-month-day, 
    #used 2012 because it has 366 days and subsetted to fit the example
    rownames(data)<-strptime(paste0("2012-",1:366),format="%Y-%j")[1:nrow(data)]
    
    #transform to xts
    data<-as.xts(data)
    
    #plot
    dygraph(data)
    

    【讨论】:

      猜你喜欢
      • 2013-10-07
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 2018-04-24
      • 1970-01-01
      • 2015-05-19
      • 2022-01-07
      相关资源
      最近更新 更多