我试图在同一张图上绘制多个时间序列。
以下是该文件的一个片段:
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 不支持图例命令吗?