I would like to remove only the top (side 3) and right-hand (side 4) borders of a plot in base plot. All of the advice that I can find calls for setting
axis = F
however, I am then forced to redraw the x and y axis and manually add the labels. Is there a more direct way to ask R to simply not plot side 3 and 4 in base plot?
The "box" around a plot is a separate graphical element from the axes, so this can be difficult to figure out because you can omit the axes entirely but still have a visible box. The presence and shape of the box is dictated by the bty (or "box type") graphical parameter, which you can set inside your plot call or using the par() global graphical parameter function.
There are several allowed values of bty: "o" (the default), "l", "7", "c", "u", "]", or "[". These correspond to the shape of the box so you have to take them literally. "n" suppresses the box.
# create some data
set.seed(1)
n <- 100
x <- rnorm(n)
y <- rnorm(n)
# demonstrate values of `par`
## with axes
layout(matrix(1:8, nrow = 2, byrow = TRUE))
lapply(c("o", "l", "7", "c", "u", "[", "]", "n"), function(arg) {
plot(x, y, bty = arg, main = sprintf("bty = '%s'", arg))
})

## without axes
dev.off()
layout(matrix(1:8, nrow = 2, byrow = TRUE))
lapply(c("o", "l", "7", "c", "u", "[", "]", "n"), function(arg) {
plot(x, y, bty = arg, main = sprintf("bty = '%s'", arg), xaxt = "n", yaxt = "n")
})

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With