Hi! I am Mike Marin and in this video we'll talk about producing box plots using R
a box plot is appropriate for summarizing the distribution of
a numeric variable. we will be working
with the lung capacity data that was introduced earlier
in this series of videos. I've already gone ahead
and imported the data into R and attached it.
we can produce a box plot
using the "box.plot" command. you can access the Help menu
by typing help and in brackets the name of the command you would like help for
or by simply throwing a question mark (?)
in front of the name the command. let's go ahead
and produce a box plot for the variable lung capacity;
recall
the box plot is a visual display of the five number summary.
let's ask R for the minimum, first quartile
median, third quartile ,and maximum to complement our box plot
we can do this using the "quantile" command
asking for quantiles for the variable
LongCap and specifically
we would like the: minimum (0), first quartile (0.25)
median (0.5), third quartile (0.75)
and maximum value (1).
now let's go ahead and make a few changes to this plot
first we may add a title using the "main" argument
as well as label the x-axis or the y-axis using the
"xlab" or "ylab" arguments.
we may also change the limits
for the y-axis using the "ylim" argument
here we'll go ahead and set our y limits to run from 0
up to 16. I also like to rotate the values
on the y-axis by setting the "las" argument equal to 1
often, we wish to compare two or more box plots that are on the same scale
for example we may wish to compare
the distribution of lung capacities for "females"
to "males". in other words we wish to compare the distribution
of a numeric variable for different groups that are formed by a categorical
variable
we may accomplish this using the "boxplot" command
plot in "lung capacity" separated
by the variable "Gender". this produces a box plot
of lung capacity for each of the groups formed by the variable Gender
as before we can add a title to
this plot using the "main" argument.
we may also produce
the same plot by using the square brackets to subset
plot a "box plot" of lung capacity only for those
whose gender is "female" and on the same
axes produce a box plot of lung capacity
only for those whose gender is "male"
the double equal sign, what does this mean? recall
that the equal sign can be used in R to assign values to objects
and that the double equal sign is used to represent
the meaning of equality in a mathematical sense. in later videos in
this series
we will discuss how to further refine these plots such as replacing that 1 and 2
with more meaningful labels. to learn more about
further refining these box plots explore the Help menu
thanks for watching this video and make sure to check out my other instructional videos