2011-02-10 46 views
2

我有以下代碼錯誤:「打<Return>看接下來的情節:」 r中

frame() 
Y = read.table("Yfile.txt",header=T,row.names=NULL,sep='') 
X = read.table("Xfile.txt",header=F,sep='') 

plot(Y$V1~X$V1,pch=20,xlim=c(0,27)) 
par(new=T) 
plot(Y$V1~X$V2,pch=20,xlim=c(0,27),col='red') 
par(new=T) 
plot(Y$V1~Y$V3,pch=20,xlim=c(0,27),col='blue') 
par(new=T) 

一切都很好,我得到了同樣的情節在3個圖表。然而,當我要劃分X $ V1,X $ V2和X $ V3數據標準化的,使得

plot(Y$V1~X$V1/Y$V2,pch=20,xlim=c(0,27)) 
par(new=T) 
plot(Y$V1~X$V2/Y$V2,pch=20,xlim=c(0,27),col='red') 
par(new=T) 
plot(Y$V1~Y$V3/Y$V2,pch=20,xlim=c(0,27),col='blue') 
par(new=T) 

我得到的消息

Hit Return to see next plot:

和圖表是不會顯示在同一個情節。任何人都可以告訴我發生了什麼事以及如何解決它?

回答

6

如果你想我不知道在公式中使用算術運算時必須使用I()函數。所以

plot(Y$V1~I(X$V1/Y$V2),pch=20,xlim=c(0,27)) 
par(new=T) 
plot(Y$V1~I(X$V2/Y$V2),pch=20,xlim=c(0,27),col='red') 
par(new=T) 
plot(Y$V1~I(Y$V3/Y$V2),pch=20,xlim=c(0,27),col='blue') 
par(new=T) 

的作品。

下面的幫助頁面formula

To avoid this confusion, the function I() can be used to bracket those portions of a model formula where the operators are used in their arithmetic sense. For example, in the formula y ~ a + I(b+c) , the term b+c is to be interpreted as the sum of b and c .


編輯。你可以在一個命令中不使用公式來完成:

plot(c(X$V1/Y$V2, X$V2/Y$V2, Y$V3/Y$V2), rep(Y$V1, 3), 
    pch=20, xlim=c(0,27), 
    col=rep(c("black", "red", "blue"), each=30) 
) 
+0

謝謝你的快速回答!令人驚訝的是我在搜索引擎上找不到任何關於這個基本內容的東西! – SnowFrog 2011-02-10 11:53:22

4

爲什麼你的錯誤,但使用points代替plot第二和第三圖形是一個更優雅的解決方案(和擺脫那些par電話)

+0

謝謝你的提示。真的很乾淨... – SnowFrog 2011-02-10 11:54:26