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.
我的目标是得到一个情节,其中有多个时代系列与一个汽车图例识别系列。在我的CSV文件中,从1996年1月起,我有5个栏目(agri, food, fuel, manu, ores)。
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?
有人知道我的代码有什么问题吗?
1 个解决方案
#1
3
Your ts
object isn't well-constructed. The series is monthly, so the frequency should be 12, not 1.
你的ts对象构造得不好。这个级数是每月的,所以频率应该是12,而不是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...
然后将它转换为xts对象,然后调用plot。xt通过调用阴谋。你真的不应该叫阴谋。直接使用xts,即使它试图将您给它的对象转换为xts对象……
x <- as.xts(RuChAgri)
plot(x, screens=factor(1, 1), auto.legend=TRUE)
#1
3
Your ts
object isn't well-constructed. The series is monthly, so the frequency should be 12, not 1.
你的ts对象构造得不好。这个级数是每月的,所以频率应该是12,而不是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...
然后将它转换为xts对象,然后调用plot。xt通过调用阴谋。你真的不应该叫阴谋。直接使用xts,即使它试图将您给它的对象转换为xts对象……
x <- as.xts(RuChAgri)
plot(x, screens=factor(1, 1), auto.legend=TRUE)