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)
これは可能ですか?同じ色の2つのyを同じ色でプロットする?
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)
これは可能ですか?同じ色の2つのyを同じ色でプロットする?
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))
plot(temp2, type="l", col="green")
lines(temp1, col="red")
うん、それはあります。 ?plot
と、その色のcol
(color)引数を参照してください。
同じプロット上でそれらの両方を取得するとして、あなたは(既存のプロット上に描画)lines
/points
を使用するか、または?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')
あなたの代わりにpar(new=TRUE)
と第二plot
を行うので、lines
/points
を使用したい場合は、単に別lines(y~x,temp2,...)
を行うには、この使用ggplot2を達成することができました。あなたのデータセットを仮定すると、次のようになります
ggplot(aes(x=x, y=y, color=category), data = dat) + geom_line()
:あなたが使用して異なる色を持つ2本のラインをプロットすることができ
x y category
1 3 A
3.2 4 B