temp1<- data.frame(x =(1:10), y=(1:10)^2)
temp2<- data.frame(x =(1:10), y=(1:10)^3)
# plot(temp1$x, with both temp1$y and temp2$y;
# want each represented by a different color)
これを行うことは可能ですか?
temp1<- data.frame(x =(1:10), y=(1:10)^2)
temp2<- data.frame(x =(1:10), y=(1:10)^3)
# plot(temp1$x, with both temp1$y and temp2$y;
# want each represented by a different color)
これを行うことは可能ですか?
plot(temp2, type="l", col="green")
lines(temp1, col="red")
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))
または、ggplot2 を使用してこれを実現することもできます。データセットが次のようになっていると仮定します。
x y category
1 3 A
3.2 4 B
次を使用して、異なる色の 2 つの線をプロットできます。
ggplot(aes(x=x, y=y, color=category), data = dat) + geom_line()
ええ、そうです。?plot
および色のcol
(color) 引数を参照してください。
両方を同じプロットに表示するには、 lines
/ points
(既存のプロットに描画する) または see?par
とnew
オプションを使用できます。
特に、現在のプロット デバイスをクリーンアップ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')
lines
/を使用したい場合は、 and secondpoints
を実行する代わりに、単に実行しますpar(new=TRUE)
plot
lines(y~x,temp2,...)