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

Creating box plots with notches


In this recipe, we will learn how to make box plots with notches, which are useful in comparing the medians of different groups.

Getting ready

We will continue to use the metals.csv example dataset for this recipe. So, let's first load it:

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

How to do it...

We shall now see how to make a box plot with notches:

boxplot(Cu ~ Source, data = metals,
varwidth=TRUE,notch=TRUE,	
main="Summary of Copper concentrations by Site")

How it works...

In the example, we set the notch argument to TRUE to create notches on each side of the boxes. If the notches of two plots do not overlap, then the medians are significantly different at the 5-percent level, which suggests that the median concentrations at the four sites as shown are not statistically different from each other.

There's more

We can set the notch.frac argument to a value between 0 and 1 to adjust the fraction of the box width that the notches should use. The default value is 0.5 and a value...