【发布时间】:2011-12-01 06:08:08
【问题描述】:
我正在尝试在同一张图表上绘制多个时间序列。
以下是文件的sn-p:
Date FP1M FP3M FP6M
2001-12-01 6.44 6.34 6.36
2002-01-01 5.70 6.00 5.99
当我将 plot() 与 lines() 结合使用时,我得到了图形,但没有得到 x(即时间)轴。
以下是代码:
z <- read.table("C:\\Users\\lenovo\\Desktop\\IRPfinal.txt",header=TRUE,sep="")
d <- as.Date((z$Date),format="%m/%d/%Y")
a <- z[,"FP1M"]
b <- z[,"FP3M"]
c <- z[,"FP6M"]
plot(d,a,xaxt="n",type="l",xlab="Timeline",lwd=5,ylab="Percent",xaxt="n",
main="Forward Premia on the US Dollar")
lines(d,b,type="l",col="red",lwd=5)
lines(d,c,type="l",col="blue",lwd=5)
legend(0,col=c("black","red","blue"),lwd=5,legend=c("FP1M","FP3M","FP6M"))
axis(1, d ,format(d, "%b %y"), cex.axis = .4)
出现以下错误:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
为什么日期轴没有正确显示?
我尝试了解决上述问题的 zoo 包,但现在我无法在图表中添加图例。zoo 不支持图例命令吗?
【问题讨论】:
-
Please insert reproducible code. -
使用的格式与显示的文件内容不符。此外,像 Oscar 的回答那样使用晶格图形可能更容易,但如果您想使用经典图形,请创建一个面板函数,在面板 1 中显示图例。请参阅
?plot.zoo中的示例。
标签: r plot time-series zoo