如何将绘图区域裁剪到 R 中数据的确切范围?

2 plot r

当我在 R 中为绘图设置限制时,我设置的限制与绘图区域的实际限制之间存在一些距离:

plot(c(1, 4), c(1, 4), ylim = c(1, 4))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

当然,我可以在最外面的刻度内设置限制使它们看起来接近绘图区域的边缘。通过单独绘制轴并允许将其绘制在绘图区域之外,我可以非常接近:

plot(c(1, 4), c(1, 4), ylim = c(1.2, 3.8), axes = FALSE)
par(xpd = TRUE)
abline(h = 4, col = "grey")  # just to show the edge of the box
axis(2, at=c(1, 4), labels = c(1, 4))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但这只是眼睁睁地看着它。所以:

如何让最外面的刻度恰好落在绘图区域的边界上?

Chr*_*den 5

xaxs = 'i'并且yaxs = 'i'在 plot 语句中将使其分别准确地拟合 x 和 y 轴的数据(details)。