2012-04-13 35 views

答えて

2
matplot(temp1$x, cbind(temp1$y, temp2$y), t="l", lty=1, col=c("red", "blue")) 

または

library(ggplot2) 
qplot(x, y, colour=which, geom="path", data=lattice::make.groups(temp1, temp2)) 
3
plot(temp2, type="l", col="green") 
lines(temp1, col="red") 
0

うん、それはあります。 ?plotと、その色のcol(color)引数を参照してください。

同じプロット上でそれらの両方を取得するとして、あなたは(既存のプロット上に描画)lines/pointsを使用するか、または?parnewオプションを見ることができます。

特に、par(new=TRUE)はありません。現在のプロットデバイスをクリーニングして、上に描画することができます(私は知っています)。だから、

# plot temp1 y vs x in blue 
plot(y~x, temp1, col='blue') 

# draw the next plot on the same plot 
par(new=TRUE) 

# plot temp2 y vs x in red, on the SAME plot (new=TRUE) 
plot(y~x, temp2, col='red') 

あなたの代わりにpar(new=TRUE)と第二plotを行うので、lines/pointsを使用したい場合は、単に別lines(y~x,temp2,...)

1

を行うには、この使用ggplot2を達成することができました。あなたのデータセットを仮定すると、次のようになります

ggplot(aes(x=x, y=y, color=category), data = dat) + geom_line() 
:あなたが使用して異なる色を持つ2本のラインをプロットすることができ
x  y category 
1  3 A 
3.2 4 B 

関連する問題