Use bty Option to Change Chart Box Styles in R

The BTY option is a powerful tool in SAS that allows users to change the characteristics of the chart boxes in their graphs. This option allows for customization of the box’s line patterns, colors, and widths. This helps to make the graph more visually appealing and easier to interpret. Additionally, it allows users to better highlight certain aspects of the data they are presenting.


You can use the function in R to create multiple plots at once.

Within the par() function, you can use the bty option to specify the style of box that should be used for individual charts.

There are six possible values you can supply to the bty option:

  • o: complete box (default)
  • n: no box
  • 7: border on top and right
  • L: border on bottom and left
  • C: border on top, left and bottom
  • U: border on left, bottom and right

The following example shows how to use the bty option in practice.

Example: How to Use bty Option to Change Box Styles

The following code shows how to use the par() function to create six scatterplots in a grid with three rows and two columns:

#define plot area as three rows and two columns
par(mfrow = c(3, 2))

#create six plots
plot(1:5, pch=19, col='red')
plot(1:10, pch=19, col='blue')
plot(1:20, pch=19, col='green')
plot(1:5, pch=19, col='purple')
plot(1:10, pch=19, col='black')
plot(1:20, pch=19, col='pink')

Notice that each scatterplot has a complete box around it since this is the default option for the bty option.

However, we can use the bty option to specify a different box style for each scatterplot:

#define plot area as three rows and two columns
par(mfrow = c(3, 2))

#create six plots with unique box styles
par(bty='o')
plot(1:5, pch=19, col='red', main='Complete Box')

par(bty='n')
plot(1:10, pch=19, col='blue', main='No Box')

par(bty='7')
plot(1:20, pch=19, col='green', main='Top and Right')

par(bty='L')
plot(1:5, pch=19, col='purple', main='Bottom and Left')

par(bty='C')
plot(1:10, pch=19, col='black', main='Top, Left, Bottom')

par(bty='U')
plot(1:20, pch=19, col='pink', main='Left, Bottom, Right')

r plot bty argument

Notice that each of the six plots now have a unique box style.

It’s also worth noting that you can specify the same box style for each plot by doing so in the first par() function:

#define plot area and use bottom+left box style for each plot
par(mfrow = c(3, 2), bty='L')

This particular example will cause each of the six plots to have a border only on the bottom and left side.

The following tutorials explain how to perform other common tasks in R:

How to Use cex to Change the Size of Plot Elements in R

x