如何在r图中调整轴从零原点开始

Dun*_*una 14 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
Run Code Online (Sandbox Code Playgroud)

然而,得到的图除了框之外在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
Run Code Online (Sandbox Code Playgroud)

42-*_*42- 15

听起来你要求'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"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Hen*_*rik 8

使用yaxs = "i"参数:

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

这将使轴在ylim点处对齐(据称为0和1 plot.ecdf).

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

box()
Run Code Online (Sandbox Code Playgroud)