Reputation: 3396
My aim is to get 1 plot in which there is multiple times series with an auto legend to identify the series. In my CSV file I have 5 columns (agri, food, fuel, manu, ores) starting from January,1996.
library(xts)
library(xtsExtra)
RuChAgri <- read.csv("https://dl.dropbox.com/u/6421260/Forum/RuChAgri.csv", sep=";")
#transform csv data according to R ts
RuChAgri <- ts(RuChAgri, start = c(1996, 1), frequency = 1)
#try to get 1 plot with multiple ts with an auto legend
plot.xts(RuChAgri, screens = factor(1, 1), auto.legend = TRUE)
When I run last line I get the error:
Error in try.xts(x) :
Error in xts(x.mat, order.by = order.by, frequency = frequency(x),
.CLASS = "ts", : NROW(x) must match length(order.by)
Does someone know what is wrong with my code?
Upvotes: 3
Views: 1572
Reputation: 176648
Your ts
object isn't well-constructed. The series is monthly, so the frequency should be 12, not 1.
RuChAgri <- ts(RuChAgri, start=c(1996, 1), frequency=12)
Then you should convert it to an xts object and then call plot.xts
by calling plot
. You really shouldn't call plot.xts
directly, even though it tries to convert the object you give it to an xts object...
x <- as.xts(RuChAgri)
plot(x, screens=factor(1, 1), auto.legend=TRUE)
Upvotes: 3