限制R中绘图中水平线的长度
Restricting the length of horizontal line in plot in R
我正在尝试使用 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所示。
开发有关 xpd
参数的评论:
来自par
帮助: xpd
参数是"A logical value or NA. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region"
插图:
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")
给出:
我正在尝试使用 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所示。
开发有关 xpd
参数的评论:
来自par
帮助: xpd
参数是"A logical value or NA. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped to the figure region, and if NA, all plotting is clipped to the device region"
插图:
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")
给出: