문제

When I set limits to a plot in R, there is some distance between the limits I set and the actual limits of the plot area:

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

enter image description here

Of course I can set the limits inside the outermost ticks so they appear to fall close to the edge of the plot area. I can get pretty close by drawing the axis separately and allowing it to be drawn outside the plot area:

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

But that's just eyeballing it. So:

How can I get the outermost ticks to fall exactly on the border of the plot area?

도움이 되었습니까?

해결책

xaxs = 'i' and yaxs = 'i' in the plot statement will cause it to fit the data exactly for the x and y axes respectively (details).

다른 팁

The plot parameters xaxs and yaxs help with this:

plot(c(1, 4), c(1, 4), xaxs="i")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top