R automatically adjusts the widths of boxes in a box plot according to the number of variables. This works fine when we have a relatively large number of variables (more than 4), but you might find that for a small number of variables, the default boxes are too wide. In this recipe, we will learn how to make the boxes narrower.
We are only using the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. We will use the airpollution.csv
example dataset for this recipe. So, let's first load it:
air<-read.csv("airpollution.csv")
We want to make a box plot summarizing the two columns in our dataset: respirable particles and nitrogen oxides. If we simply use the boxplot
command, we get a box plot with very wide boxes:
boxplot(air,las=1)
Let's improve the look of the graph by making the boxes narrower:
boxplot(air,boxwex=0.2,las=1)