我想在同一個圖上繪製多個時間序列。傳說中的動物園命令
下面是該文件的一個片段:
Date FP1M FP3M FP6M
2001-12-01 6.44 6.34 6.36
2002-01-01 5.70 6.00 5.99
當我使用結合圖()用線(),我得到的圖形,但不是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
爲什麼日期軸沒有顯示正確嗎?
我嘗試瞭解決上述問題的動物園包,但現在我無法將圖例添加到圖形中。動物園不支持圖例命令嗎?
使用不符合所示的文件內容格式。此外,如果您想使用經典圖形創建一個面板函數,在面板1中顯示圖例,則可能更容易使用格圖形。請參見'plot.zoo'中的示例。 –