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).
How to crop plot area to the exact range of your data in R?
Question
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))
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))
But that's just eyeballing it. So:
How can I get the outermost ticks to fall exactly on the border of the plot area?
Solution
OTHER TIPS
The plot parameters xaxs
and yaxs
help with this:
plot(c(1, 4), c(1, 4), xaxs="i")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow