2012-02-07 156 views
0

由於某些原因,如果我嘗試使用以下代碼顯示數據,我會得到正確的座標軸,但實際數據不會繪圖。有什麼建議麼?當在R中指定座標軸時,數據點不顯示

par(bg="lightgray") 
adates <-as.Date(row.names(try),format="%Y-%m-%d") 
plot(try[,1],x=adates,type="o",axes=FALSE, ann=FALSE) 
usr <- par("usr") 
rect(usr[1], usr[3], usr[2], usr[4], col="cornsilk", border="black") 
lines(try[,1], col="blue") 

axis(2,col.axis="blue",,at=pretty(try[,1]),las=1,labels=sprintf("$%1.0f",pretty(try[,1]/1000)),cex.axis=.75) 

axis.Date(1, at=pretty(adates), label=format(pretty(adates),"%y")) 
box() 
title(main="This is a graph", font.main=4, col.main="red",xlab="Date",ylab="$ (in $1000s)") 
+0

顯示您的數據示例,'嘗試'。 – 2012-02-07 12:56:05

+0

......並且不要調用你的數據'try',因爲這是一個處理錯誤的函數。 – 2012-02-07 13:47:23

+0

你知道日期是以1970年爲單位的天數表示的數值,對吧? – 2012-02-07 13:47:31

回答

1

遺忘的代碼中的所有其他位,看看

plot(try[,1],x=adates,type="o",axes=FALSE, ann=FALSE) 

的第一個參數情節是矢量x座標,在此情況下是try[,1]。然後,您可以使用x=adates提供另一組x座標。所以現在你有兩套x-coords但沒有y-coords。