17

为了绘制三个变量 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 处有两条水平线(虚线)。并且,盒子的原点在垂直轴上的零以下有一个空格,在水平轴上零的左边有一个空格。您能否建议如何删除这些空间和附加行。我想要但无法发布情节。

编辑:可以按如下方式生成示例数据:

样本数据

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
4

3 回答 3

16

听起来您正在询问“xaxs”和“yaxs”的不同设置提供的样式,也许还有“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"))

在此处输入图像描述

于 2013-07-02T14:49:53.103 回答
8

使用yaxs = "i"参数:

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

这将在ylim点处对齐轴(假设为 0 和 1 plot.ecdf)。

如果您还想删除 0 和 1 处的虚线,只需调用box()

box()
于 2013-07-02T14:42:27.807 回答
1

您可以使用参数xlim,ylimcol.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"))  

在此处输入图像描述

或者,您可以只使用泛型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"))

在此处输入图像描述

于 2013-07-02T14:24:40.493 回答