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 to do it...

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% 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 of 1 gives notches using the entire width of the box, effectively producing a box plot without notches.

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

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