# bty in R: What is Control box type

The bty option of the par() function is used to control the box style of base charts.

When using plotting functions, such as plot(), hist(), etc., you can specify the bty parameter to change the appearance of the box surrounding the plot.

It accepts different character values to specify the style of the box:

1. o: complete box (default parameter)
2. n: no box
3. 7: top + right
4. L: bottom + left
5. C: top + left + bottom
6. U: left + bottom + right

## Example 1: Basic usage of “bty” in par()

``````par(mfrow = c(2, 3))

# Create data
x <- c(1, 2, 3, 4, 5, 6, 7)
y <- c(1, 8, 27, 64, 125, 216, 343)

# First graph
par(bty = "l")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "bottom left")

# Second graph
par(bty = "o")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "Complete box")

# Third graph
par(bty = "c")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "top + left + bottom")

# Fourth graph
par(bty = "n")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "no box")

# Fifth graph
par(bty = "U")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "left + bottom + right")

# Sixth graph
par(bty = "7")
plot(x, y, pch = 23, col = "black", bg = "yellow", lwd = 1, cex = 1.5, xlab = "top + right")``````

Output

## Example 2: Using boxplot() function

Boxplot measures how well the data is distributed in the data set.

It divides the data set into three quartiles. This graph represents the data set’s minimum, maximum, median, first, and third quartiles.

``````par(mfrow = c(2, 3))

# Create data
a <- seq(1, 21) + 3 * runif(21, 0.3)
b <- seq(1, 21) ^ 2 + runif(21, 0.98)

# First graph
par(bty = "l")
boxplot(a, col = "purple", xlab = "bottom & left box")

# Second graph
par(bty = "o")
boxplot(b, col = "purple", xlab = "complete box", horizontal = TRUE)

# Third graph
par(bty = "c")
boxplot(a, col = "purple", xlab = "up & bottom & left box", width = 0.5)

# Fourth graph
par(bty = "n")
boxplot(a, col = "purple", xlab = "no box")

# Fifth graph
par(bty = "U")
boxplot(a, col = "purple", xlab = "left + bottom + right")

# Sixth graph
par(bty = "7")
boxplot(b, col = "purple", xlab = "top + right")
``````

Output

That is it.

1. Omigosh!!!!