boxPlot {openintro}R Documentation

Box plot

Description

An alternative to boxplot. Equations are not accepted. Instead, the second argument, fact, is used to split the data.

Usage

boxPlot(x, fact = NULL, horiz = FALSE, width = 2/3, lwd = 1, lcol = "black", medianLwd = 2, pch = 20, pchCex = 1.8, col = fadeColor("black", "44"), add=FALSE, key=NULL, axes = TRUE, xlab = "", ylab = "", xlim = NULL, ylim = NULL, ...)

Arguments

x A numerical vector.
fact A character or factor vector defining the grouping for side-by-side box plots.
horiz If TRUE, the box plot is oriented horizontally.
width The width of the boxes in the plot. Value between 0 and 1.
lwd Width of lines used in box and whiskers.
lcol Color of the box, median, and whiskers.
medianLwd Width of the line marking the median.
pch Plotting character of outliers.
pchCex Size of outlier character.
col Color of outliers.
add If FALSE, a new plot is created. Otherwise, the boxplots are added to the current plot for values of TRUE or a numerical vector specifying the locations of the boxes.
key The order in which to display the side-by-side boxplots. If locations are specified in add, then the elements of add will correspond to the elements of key.
axes Whether to plot the axes.
xlab Label for the x axis.
ylab Label for the y axis.
xlim Limits for the x axis.
ylim Limits for the y axis.
... Additional arguments to plot.

Author(s)

David Diez

See Also

histPlot, dotPlot, densityPlot

Examples

data(run10)
par(mfrow=1:2)

#===> comparison 1 <===#
boxPlot(run10$time)
boxplot(run10$time)

#===> comparison 2 <===#
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))
boxplot(run10$time ~ run10$gender)

#===> modifications using boxPlot <===#
par(mfrow=c(2,2))
boxPlot(run10$time, run10$gender)
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))
# 'key' can be used to restrict to only the
# desired groups

#===> combine boxPlot and dotPlot <===#
data(tips)
par(mfrow=c(1,1))
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))

#===> adding a box <===#
par(mfrow=1:2)
boxPlot(run10$time[run10$gender=='M'], xlim=c(0,3))
boxPlot(run10$time[run10$gender=='F'], add=2, axes=FALSE)
axis(1, at=1:2, labels=c('M', 'F'))
boxPlot(run10$time[run10$gender=='M'], ylim=c(0,3), horiz=TRUE)
boxPlot(run10$time[run10$gender=='F'], add=2, horiz=TRUE, axes=FALSE)
axis(2, at=1:2, labels=c('M', 'F'))

[Package openintro version 1.0 Index]