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

时间:2014-03-03 21:37:53

标签: r plot

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

plot(c(1, 4), c(1, 4), ylim = c(1, 4))

enter image description here

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

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))

enter image description here

但这只是眼球。所以:

如何让最外面的刻度线在绘图区域的边框上完全

2 个答案:

答案 0 :(得分:4)

plot语句中的

xaxs = 'i'yaxs = 'i'将使它分别适合x和y轴的数据(details)。

答案 1 :(得分:2)

情节参数xaxsyaxs有助于此:

plot(c(1, 4), c(1, 4), xaxs="i")