Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 \n 
(without outliers)")

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...