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

标签 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处还有两条水平线(虚线)。并且,盒子的原点在垂直轴上有一个零以下的空间,在水平轴上有一个零左的空间。可能您建议如何删除这些空间和其他行。我想要但无法发布情节。

编辑:
可以如下生成样本数据:

样本数据

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

最佳答案

听起来您正在要求由“ 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"))

关于r - 如何在R图中将轴从零原点开始调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427717/

相关文章:

r - 使用弹性表编程

r - 当列名包含空格和特殊字符时从 data.table 包中读取?

r - 如何以编程方式编辑 R markdown YAML header ?

r - 如何跨 data.frame 列应用函数?

r - 使用 dplyr full_join 扩展 data.frame 的 grid

r - R-install.packages在计算引擎上的Coreos上的Docker中不起作用

r - 从数据框中选择行

r - 访问 R 中的嵌套列表

r - 将汇总统计数据(甚至原始数据点)添加到闪避位置箱线图

r - 仅当另一列中的相应值在 r 中也重复时,才提取一列中具有重复值的行