【问题标题】:multiple line on same plot for timeseries时间序列的同一图上的多条线
【发布时间】:2015-05-28 02:58:51
【问题描述】:

下表有366天的数据:

od
    month dayofmonth total    ad  aont
1       1          1    27     9    18
2       1          2    31    24     7
3       1          3    30    25     5
4       1          4    29    15    14
5       1          5    27     1    26
6       1          6    30    18    12
7       1          7    31     8    23
8       1          8    30     9    21
9       1          9    25    23     2
10      1         10    31    15    16
11      1         11    27    17     7
12      1         12    27     3    24
13      1         13    26    11    15
14      1         14    28    12    


library(zoo)
require(xts)

Dates <- seq(as.Date(f, "%Y - %m - %d"), as.Date(t, "%Y - %m - %d"), "day")


total<- xts(od$total, order.by = Dates)
dont<- xts(od$ad, order.by = Dates)
adont<- xts(od$aont, order.by = Dates)

我使用zoo 包现在我想在同一个图中绘制多条线

【问题讨论】:

    标签: r time-series xts zoo


    【解决方案1】:

    在情节调用中使用plot.type="single" 可以帮助解决这个问题。

        #open libraries 
    library(xts)
    library(zoo)
    #set some random variables
    a=rnorm(100)
    b=rnorm(100)
    #and some time series
    c=seq(as.Date("2000/1/1"), by = "week", length.out = 100)
    d=cbind(a,b)
    #make it into an zoo object
    d=as.zoo(d, order.by=c)
    plot.zoo(d, 
             plot.type = "single", 
             col = c("red", "blue"))
    

    【讨论】:

      【解决方案2】:

      创建动物园对象,然后绘制:

      library(ggplot2)
      library(zoo)
      
      z <- zoo(od[3:5], as.Date(paste(2012, od$month, od$dayofmonth, sep = "-")))
      
      autoplot(z, facet = NULL)
      

      【讨论】:

        猜你喜欢
        • 2018-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-25
        • 1970-01-01
        • 2016-12-29
        • 1970-01-01
        • 2018-09-11
        相关资源
        最近更新 更多