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:
- o: complete box (default parameter)
- n: no box
- 7: top + right
- L: bottom + left
- C: top + left + bottom
- 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.
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
Omigosh!!!!
good. thank you !