下表有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
包我想在同一个地块中绘制多行
答案 0 :(得分:0)
创建zoo对象,然后绘制:
library(ggplot2)
library(zoo)
z <- zoo(od[3:5], as.Date(paste(2012, od$month, od$dayofmonth, sep = "-")))
autoplot(z, facet = NULL)
答案 1 :(得分:0)
在情节调用中使用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"))