我正在尝试使用abline
代码如下:
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")
我得到的输出是
我在寻找什么 是
如何将abline
绘制的线条限制在绘图区域内,如第2幅图所示。
答案 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")
给出:
而
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")
给出:
最后,
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")
给出: