Constructing a box and whiskers plot
Box plots, also known as box and whisker diagrams, assist us in studying the distribution of the data and also provide us with information regarding the outliers. Box plots display the minimum, maximum, median, and interquartile range of each variable in the data. The Flowing Data website provides a very detailed description on how to read a box plot. The following plot shows the distribution and the outliers of wage data. We observe that as the level of education increases, the wage earned also increases.
Getting ready
Box plots are generated in R using the basic R package. The wage data used to generate the box plot is available with the ISLR
package and hence needs to be loaded in R. The following lines of code are used to load the package:
install.packages("ISLR") library("ISLR")
How to do it…
We can get a general idea about the distribution of data using the summary()
function:
summary(Wage)
We set the margin of the plot using the mar
argument within the...