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


In this recipe, you will learn how to make box plots that are useful in comparing the spread of values in different measurements.

Getting ready

First, we need to load the metals.csv example data file that contains measurements of metal concentrations in London's air (you can download this file from the code download section of the book's companion website):

metals<-read.csv("metals.csv",header=TRUE)

How to do it...

We can make a box plot to summarize the metal concentration data using the boxplot() command as follows:

boxplot(metals,
xlab="Metals",
ylab="Atmospheric Concentration in ng per cubic metre",
main="Atmospheric Metal Concentrations in London")

How it works...

The main argument, the boxplot() function, takes a set of numeric values (in the form of a vector or data frame). In our first example, we used a dataset containing numerical values of air pollution data from London. The dark line inside the box for each metal represents the median of values for that metal. The...