2013-07-02 4 views
11

を開始するために軸を調整することができます。どのように私はRに次のように使用され、三つの変数、X1、X2およびX3の経験累積密度をプロットするには、Rのプロットにゼロ原点から

plot.ecdf(x1, col="blue", 
    main="Distribution XYZ", 
    xlab="x_i", ylab="Prob(x_i<=y)") 

lines(ecdf(x2), col="red") # adds a line 
lines(ecdf(x3), col="green") # adds line 
legend(600,0.6, # places a legend from (x,y)=(600,0.6) on 
     c("x1","x2","x3"), # puts text in the legend 
     lty=c(1,1,1), # gives the legend appropriate symbols (lines) 
     lwd=c(1,1,1),col=c("blue","red","green")) # gives the legend lines the correct color and width 

結果のプロットただし、ボックスの外に0と1に2本の水平線(破線)があります。そして、ボックスの原点は、垂直軸上のゼロ以下のスペースと、水平軸上のゼロの左のスペースとを有する。これらのスペースと追加の行を削除する方法を提案してください。私は望みましたが、プロットを投稿できませんでした。

EDITED: 次のようにサンプルデータを生成することができます。

サンプルデータ

n <- 1000; u <- runif(n) 
a <- -4.46; b <- 1.6; c <- -4.63 
d <- (a * u) + (b * ((1.5 * (u ** 2)) - 0.5)) + (c * ((2.5 * (u ** 3)) - (1.5 * u))) 
x1 <- -126/d; x2 <- -131/d; x3 <- -187/d 
+1

最小限の作業例を提供できますか?基本的には、コードを実行するための最小限のデータセットです。 –

+0

@TylerRinkerサンプルデータが含まれています。 – Duna

+0

答えはいくつかの面で間違っていました(それは新しい機能ではありません)。不完全なものでした(xlim仕様の追加が必要な要求された軸を制御しなかったため)。 –

答えて

13

ですね、そしておそらく 'XLIM':

試してみてください。

plot.ecdf(x1, col="blue", 
    main="Distribution XYZ", 
    xlab="x_i", ylab="Prob(x_i<=y)", 
    xaxs="i",yaxs="i", xlim=c(0,1000)) 

lines(ecdf(x2), col="red")  
lines(ecdf(x3), col="green") 
legend(600,0.6, 
     c("x1","x2","x3"), 
     lty=c(1,1,1), 
     lwd=c(1,1,1),col=c("blue","red","green")) 

enter image description here

+0

はい、まさに私が欲しいものです。最後にbox()を呼び出すと、 – Duna

1

あなたは引数xlimylimcol.01lineを使用することができます。

x1 = runif(100) 
x2 = runif(100) 
x3 = runif(100) 
plot.ecdf(x1, col="blue", main="Distribution XYZ",xlab="x_i", ylab="Prob(x_i<=y)", ylim=c(0, 1), xlim=c(0,1), col.01line="white", verticals=FALSE) 
lines(ecdf(x2), col="red", col.01line="white") 
lines(ecdf(x3), col="green", col.01line="white") 
legend(600,0.6,c("x1","x2","x3"), lty=c(1,1,1), lwd=c(1,1,1),col=c("blue","red","green")) 

enter image description here

代わりに、あなただけの一般的なplotを使用することができます。

f1 = ecdf(x1) 
f2 = ecdf(x2) 
f3 = ecdf(x3) 
pts = seq(0, 1, 0.01) 
plot(pts, f1(pts), col="blue", type="b", xlab="x_i", ylab="Prob(x_i<=y)", pch=16, main="Distribution XYZ") 
lines(pts, f2(pts), col="red", type="b", pch=16) 
lines(pts, f3(pts), col="green", type="b", pch=16) 
legend("topleft", c("x1","x2","x3"), fill=c("blue","red","green")) 

enter image description here

+0

ここで私のサンプルデータ( 'runif(100)')をプロットしたことに注意してください。データを使用する場合は、 'pts'を' seq(0、1000、0.1) 'などに変更したいかもしれません。 – user1981275

+0

コードで不要な水平線が削除されました。しかし、0に壊れた水平線があります。私もそれを削除したいです – Duna

7

yaxs = "i"引数を使用します。

plot.ecdf(x1, col="blue", 
    main="Distribution XYZ", 
    xlab="x_i", ylab="Prob(x_i<=y)", yaxs = "i") 

これはおそらく0でylimポイント(で軸を合わせますがplot.ecdfの場合は1)。あなたも0と1で点線を削除したい場合は

、ちょうどbox()呼び出し:あなたは「xaxs」と「yaxs」の異なる設定によって提供されるスタイルを求めているよう

box() 
関連する問題