#### How to plot overlaying time series in R?

``````x.Date <- as.Date(dataset1\$Date)
x <- zoo(dataset1\$Value, x.Date)
plot(x)
``````

5 个回复

``````set.seed(1)
xz = zoo(ts(rnorm(20), frequency = 4, start = c(1959, 2)))
yz = zoo(ts(rnorm(20), frequency = 4, start = c(1959, 2)))
# Basic approach
plot(xz)
lines(yz, col = "red")
# Panels
plot.zoo(cbind(xz, yz))
# Overplotted
plot.zoo(cbind(xz, yz),
plot.type = "single",
col = c("red", "blue"))
``````

``````set.seed(1)
x = ts(rnorm(20), frequency = 4, start = c(1959, 2))
y = ts(rnorm(20), frequency = 4, start = c(1959, 2))
ts.plot(x, y, gpars = list(col = c("black", "red")))
``````

``````    ts.plot(..., gpars = list())
``````

gpars 是图形参数，您可以在其中指定绘图的图形组件。

``````           [,1] [,2]  [,3]  [,4] [,5]  [,6]  [,7]  [,8]   [,9] [,10]
V3     1951 1100   433  5638 1760  2385  2602 11007   2490   421
V5      433  880   216  4988  220  8241 13229 18704   6289   421
V7     4001  440   433  3686  880  9976 12795 21036  13229  1263
V9     2385 1320   650  8241  440 12795 13229 19518  11711  1474
V11    4771  880  1084  6723    0 17783 17566 27326  11060   210
V13    6940  880  2168  2602 1320 21036 16265 10843  15831  1474
V15    3903 1760  1951  3470    0 18217 14964     0  13663  2465
V17    4771  440  2819  8458  880 25591 24940  1518  17783  1895
V19    7807 1760  5205  2385    0 14096 22771 13880  12578  1263
V21    5205  880  5205  6506  880 28410 18217 13229  19952  1474
V23    6506 1760  5638  7590  880 14747 26675 11928  12795  1474
V25    7373  440  5855 10626    0 19301 21470 15398  19952  1895
V27    5638 2640  6289     0  880 16482 20603 30796  14313  2316
V29    8241  440  6506  6723  880 11277 35784 25157  23205  4423
V31    7373 2640  6072  8891  220 17133 27109 31013  27287  4001
V33    6723  660  5855 14313  660  6940 26892 17566  24111  4844
V35    9325 2420  9325 12578    0  6506 30796 34483  23422  5476
V37    4771  440  6872 12361  880  9325 36218 25808  30362  4844
V39    9976 2640  7658 12361  440 11277 36001 31013  40555  4633
V41   10410  880  6506 12795  440 26241 33398 27976  24940  5686
V43    5638 2200  7590 14313    0  9976 34483 29928  33832  6108
V45   10843  440  8675 11711  440  7807 29278 24940  43375  4633
V47    8675 1760  8891 13663    0  9108 38386 31230  33398  4633
V49   10410 1760  9542 13880  440  8675 39051 31446  42507  5476
.   .   .   .   .   .   .   .   .
``````

``````    ts.plot(time,gpars= list(col=rainbow(10)))
``````

``````library(ggplot2)

dta <- data.frame(year = 2012,
month = rep(seq(1,9),each=10),
day = sample(seq(1,20),90,replace=T),
Group = sample(c('A','B'),90,replace=T),
Value = seq(1,90)
)

dta\$Date <- apply(dta[,c('year','month','day')],1,paste,sep='',collapse='-')
dta\$Date <- as.Date(dta\$Date)

qplot(Date,Value,data=dta,geom='line',color=Group)
``````

``````dataset1\$Group <- 'dataset1'
dataset2\$Group <- 'dataset2'
dta <- rbind(dataset1,dataset2)
dta\$Date <- as.Date(dta\$Date)
``````

``````library("tseries")
comb_ts <- cbind(x1, x2) # please make sure the length of both your timeseries
plot.ts(comb_ts, plot.type = "single")
``````

`````` library(quantmod)
sbi <- getSymbols("SBIN.BO", src="yahoo",auto.assign = F)
rel <- getSymbols("RELIANCE.NS", src="yahoo",auto.assign = F)
infy <- getSymbols("INFY.NS", src="yahoo",auto.assign = F)

library(highcharter)
highchart(type = "stock")  %>%
``````
1 如何在 R 中绘制叠加时间序列

2 绘制叠加时间序列

3 如何在R中绘制时间序列EVI

2018-12-02 18:30:14 0 46   r
4 R：叠加时间序列

5 在R中绘制时间序列

6 绘制R中的时间序列

7 在R中绘制时间序列

9 如何在R中绘制多个因素的时间序列数据

10 如何在R中绘制多个时间序列数据