同じグラフに複数の時系列をプロットしようとしています。
以下はファイルのスニペットです。
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パッケージを試しましたが、グラフに凡例を追加できません。legendコマンドはzooでサポートされていませんか?