限制R中图中水平线的长度

时间:2015-02-05 09:14:50

标签: r plot

我正在尝试使用abline

在地块上绘制水平线

代码如下:

plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

我得到的输出是

Graph I am getting

我在寻找什么  是

Desired polt

如何将abline绘制的线条限制在绘图区域内,如第2幅图所示。

1 个答案:

答案 0 :(得分:3)

开发有关xpd参数:

的注释

来自par帮助: xpd参数是"逻辑值或NA。如果为FALSE,则所有绘图都被剪切到绘图区域,如果为TRUE,则所有绘图都将剪切到图形区域,如果为NA,则所有绘图都将剪切到设备区域"

<强> 插图:

par(xpd=T)
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here

par(xpd=F) # this is the default value
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here

最后,

par(xpd=NA,mfrow=c(1,2))
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here