A box plot is a chart that illustrates groups of numerical data through the use of quartiles. A simple box plot can be created in R with the boxplot function. In the example below, data from the sample "chickwts" dataset is used to plot the the weight of chickens as a function of feed type.
boxplot(NumericVector ~ GroupingVariable)
> boxplot(chickwts$weight ~ chickwts$feed)
The resulting box plot is very simple. However, users can define arguments to fully customize the appearance of the plot. Each argument is entered within the boxplot function and separated by a comma. When using the boxplot function it's often easiest to start with a standard template that lists the most common arguments with a NULL or DEFAULT value (example below). The user can then define whatever arguments they choose to customize the plot.
> boxplot(NumericVector ~ GroupingVariable,
horizontal = FALSE,
outline = TRUE,
range = 1.5,
log = "",
notch = FALSE,
boxwex = 0.8,
staplewex = 0.5,
outwex = 0.5,
varwidth = FALSE,
border = NULL,
col = NULL)
The format of the above string includes extra returns after each argument. R does not recognize extra returns in a string, the extra returns are included to make visual identification of each argument quicker and easier.
Common Box Plot Arguments
Definitions and examples for a few of the more common arguments are provided in the table below. View the subpages under Data Visualization > Box Plot to learn more about the use of these arguments in box plots.