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.

Getting ready

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

metals<-read.csv("metals.csv")

How to do it...

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

boxplot(metals[,-1],outline=FALSE,
main="Summary of metal concentrations by Site 
 
(without outliers)")
How to do it...

How it works...

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.

See also

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.46.181