简体   繁体   English

绘制具有3条曲线时间序列数据的图形

[英]plotting a graph with 3 curves time series data

I have a pretty basic questions, but I wasn't able to find an answer. 我有一个非常基本的问题,但找不到答案。 I would like to create a graph with three curves (time series data) without using ts.plot. 我想不使用ts.plot创建具有三个曲线(时间序列数据)的图形。 Here are the three data sets: 这是三个数据集:

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)

I now want to plot the three curves. 我现在想绘制三个曲线。 I wrote this code: 我写了这段代码:

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

But it doesn't work. 但这是行不通的。

any suggestions? 有什么建议么? :) :)

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM