Plot and boxplot in R without borders

R can be pretty counter-intuitive at times, usually for historical reasons. Here’s one I’ve forgotten several times: drawing a plot and a boxplot without the border/box around it. The default (top row) is the plot with a border/box around it.

For the plot() function, we need the argument bty=”n”, that’s the box type “n” (for none, I guess). For the boxplot, we need frame=FALSE, which behind the scenes sets the same graphical parameter. Oddly enough, frame=FALSE is not mentioned in the help on the boxplot() function.

The precise code for these plots: a bunch of values in myvalues, some random values in xrandom to spread out the points, and then this:

par(mfrow=c(2,2)) # 2 x 2 plots
plot(myvalues ~ xrandom, xlim=c(0.5, 1.5), xlab="", ylab="")
boxplot(myvalues, xlim=c(0.5, 1.5), xlab="", ylab="")
plot(myvalues ~ xrandom, xlim=c(0.5, 1.5), xlab="", ylab="", bty="n")
boxplot(myvalues, xlim=c(0.5, 1.5), xlab="", ylab="", frame=FALSE)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: