2012-05-15 24 views
0

我試圖在this數據中繪製變量「ipen」對「年份」的增長樣條。我使用的代碼是:R:ylim和xlab/ylab在plot()for grofit package not working

grofit <- read.csv('http://dl.dropbox.com/u/1791181/grofit.csv') 
# install.packages(c("grofit"), dependencies = TRUE) 
require(grofit) 
growth = gcFitSpline(grofit$year, grofit$ipen) 
plot(growth) 

這工作正常,併產生下面的情節。但問題是(a)我無法使用xlabylab選項更改默認標籤,並且(b)plot()語句中的ylim=c(0,100)無法將x軸的比例更改爲(0,100)。我在grofit()文檔中找不到任何指針。 this

+1

我會使用'plot.gcFitSpline()'函數並對其進行自定義。 –

回答

2

不要直接使用plotgcFitSpline結果,而是使用str(growth)探索曲線擬合對象的結構,並確定要繪製什麼,或者看plot.gcFitSpline代碼(只需鍵入該函數的名稱,而不括號中的控制檯,然後按Enter)

例如:

growth = gcFitSpline(grofit$year, grofit$ipen) 

plot (grofit$year, grofit$ipen, pch=20, cex=0.8, col="gray", ylim=c(0, 100), 
    ylab="Growth", xlab="Year", las=1) 
points(growth$fit.time, growth$fit.data, t="l", lwd=2) 

這給:

result grofit plot

+1

絕對完美!非常感謝,尼科。 – user702432

1

其實,我覺得grofit文檔確實有一個關於這個指針:

...其他圖形參數也可以作爲參數傳遞[原文]。這目前沒有效果,只是爲了滿足通用函數的要求。

您可能需要重寫具體到你想要的圖形參數plot.gcFitSpline功能,但有可能是一個原因,功能是它的方式。

順便說一句,我不確定給你的數據和你使用的軟件包同名是個好主意。