Skip to content
Prev 361966 / 398506 Next

What's box() (exactly) doing?

Hi Marius,
There are a few things that are happening here. First, the plot area
is not going to be the same as your x and y limits unless you say so:

# run your first example
par("usr")
[1] -0.04  1.04 -0.04  1.04

# but
plot(NA, type = "n", ann = FALSE, axes = FALSE,
 xlim = 0:1, ylim = 0:1,xaxs="i",yaxs="i")
box()
rect(xleft = 0, ybottom = 0, xright = 1, ytop = 1, col = "grey80")
par("usr")
[1] 0 1 0 1

Second, the "rect" function is automatically clipped to the plot area,
so you may lose a bit at the edges if you don't override this:

par(xpd=TRUE)
rect(...)
par(xpd=FALSE)

Finally your second example simply multiplies the first problem by
specifying a layout of more than one plot. Applying the "xaxs" and
"yaxs" parameters before you start plotting will fix this:

par(xaxs="i",yaxs="i")

Jim

On Fri, Jun 24, 2016 at 12:29 PM, Marius Hofert
<marius.hofert at uwaterloo.ca> wrote: