用 3 条曲线时间序列数据绘制图表

plotting a graph with 3 curves time series data

我有一个非常基本的问题,但找不到答案。 我想在不使用 ts.plot 的情况下创建一个包含三个曲线(时间序列数据)的图表。 下面是三个数据集:

a1 <- seq(as.Date("2001-01-01"),as.Date("2021-01-01"),"years")
a2 <- rnorm(21,10,1)
Dollar <- data.frame(a1,a2)
dates <- as.Date(Dollar[,1], "%d.%m.%Y",tz="GMT") 
xtsplot1 <- as.xts(Dollar[,2], dates)


b1 <- seq(as.Date("2001-01-01"),as.Date("2021-01-01"),"years")
b2 <- rnorm(21,10,1)
EURO <- data.frame(b1,b2)
xtsplot2 <- as.xts(EURO[,2], dates)

c1 <- seq(as.Date("2001-01-01"),as.Date("2021-01-01"),"years")
c2 <- rnorm(21,10,1)
YEN <- data.frame(c1,c2)
xtsplot3 <- as.xts(Dollar[,2], dates)

我现在想绘制这三个曲线。我写了这段代码:

plot(xtsplot1, xtsplot2, xtsplot3, xaxt = "n", xlab = "Time", ylab = "Value", col = 1:3, ann = FALSE)

但是不行。

有什么建议吗? :)

您可以按如下方式使用 matplot:

matplot(cbind(xtsplot1, xtsplot2, xtsplot3), xaxt = "n", xlab = "Time", ylab = "Value", col = 1:3, ann = FALSE, type = 'l')