Including or excluding outliers

In this recipe, we will learn how to remove outliers from a box plot. This is usually not a good idea because highlighting outliers is one of the benefits of using box plots. However, sometimes extreme outliers can distort the scale and obscure the other aspects of a box plot, so it is helpful to exclude them in those cases.

Let's continue using the metals.csv example dataset. So, let's first make sure it has been loaded:

Once again, we will use the base graphics boxplot() function with a specific argument to make our metal concentrations box plot without outliers:

How to do it...

We used the outline argument in the boxplot() function call to suppress the drawing of outliers. By default, outline is set to TRUE. To exclude outliers, we set it to FALSE.

In the Adjusting the extent of plot whiskers outside the box recipe, later in the chapter, we will learn how to extend the whiskers of a box plot, which is another way of eliminating outliers by changing the definition of the cutoff value for an outlier.