Reputation: 123
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. 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? :)
Upvotes: 0
Views: 146
Reputation: 1212
You could use matplot as follows:
matplot(cbind(xtsplot1, xtsplot2, xtsplot3), xaxt = "n", xlab = "Time", ylab = "Value", col = 1:3, ann = FALSE, type = 'l')
Upvotes: 2