Plot Vertical Box-and-Whisker Plots for Variables
Plots a series of vertical box-and-whisker plots (Garrett, 1988)where the individual plots represent the data subdivided by variables. Optionally the y-axis may be scaled logarithmically (base 10). A variety of other plot options are available, see Details and Note below.
bwplots.by.var(xmat, log = FALSE, wend = 0.05, notch = FALSE, xlab = "Measured Variables", ylab = "Reported Values", main = "", label = NULL, plot.order = NULL, xpos = NA, las = 1, cex.axis = 1, adj = 0.5, colr = 8, pch = 3, ...)
xmat |
the data matrix or data frame containing the data (variables). |
log |
to display the data with logarithmic (y-axis) scaling, set |
wend |
the locations of the whisker-ends has to be defined. By default these are at the 5th and 95th percentiles of the data. Setting |
notch |
determines if the boxplots are to be “notched” such that the notches indicate the 95% confidence intervals for the medians. The default is not to notch the boxplots, to have notches set |
xlab |
a title for the x-axis, by default |
ylab |
a title for the y-axis, by default |
main |
a main title may be added optionally above the display by setting |
label |
by default the character strings defining the variables are used to label the boxplots along the x-axis. Alternate labels can be provided with |
plot.order |
provides an alternate order for the boxplots. By default the boxplots are plotted in alphabetical order of the factor variables. Thus, |
xpos |
the locations along the x-axis for the individual vertical boxplots to be plotted. By default this is set to |
las |
controls whether the x-axis labels are written parallel to the x-axis, the default |
cex.axis |
controls the size of the font used for the factor labels plotted along the x-axis. By default this is |
adj |
controls justification of the x-axis labels. By default they are centred, |
colr |
by default the boxes are infilled in grey, |
pch |
by default the plotting symbol for the subset maxima and minima are set to a plus, |
... |
further arguments to be passed to methods. For example, the size of the axis titles by setting |
There are two ways to provide data to this function. Firstly, if all the variables in a data frame are to be displayed, and there are no factor variables, the data frame name can be entered for xmat
. However, if there are factor variables, or only a subset of the variables are to be displayed, the data are entered via the cbind
construct, see Examples below.
In a box-and-whisker plot there are two special cases. When wend = 0
the whiskers extend to the observed minima and maxima that are not plotted with the plus symbol. When wend = 0.25
no whiskers or the data minima and maxima are plotted, only the medians and boxes representing the span of the middle 50% of the data are displayed.
Long variable names can lead to display problems, changing the las
parameter from its default of las = 1
which plots subset labels parallel to the axis to las = 2
, to plot perpendicular to the axis, can help. It may also help to use label
and split the character string into two lines, e.g., by changing the string "Specific Conductivity"
that was supplied to replace the variable name SC
to "Specific\nConductivity"
. If this, or setting las = 2
, causes a conflict with the x-axis title, if one is needed, the title can be moved down a line by using xlab = "\nPhysical soil properties"
. In both cases the \n
forces the following text to be placed on the next lower line.
If there are more than 7 labels (variables) and no alternate labels are provided las
is set to 2
, otherwise some variable names may fail to be displayed.
The notches in the boxplots indicate the 95% confidence intervals for the medians and can extend beyond the upper and lower limits of the boxes indicating the middle 50% of the data when subset population sizes are small. The confidence intervals are estimated using the binomial theorem. It can be argued that for small populations a normal approximation would be better. However, it was decided to remain with a non-parametric estimate to be consistent with the use of non-parametric statistics in this display.
Any less than detection limit values represented by negative values, or zeros or other numeric codes representing blanks in the data, must be removed prior to executing this function, see ltdl.fix.df
.
Any NA
s in the data vectors are removed prior to preparing the boxplots.
For a summary statistics display to complement the graphics see gx.summary.mat
.
Robert G. Garrett
Garrett, R.G., 1988. IDEAS - An Interactive Computer Graphics Tool to Assist the Exploration Geochemist. In Current Research Part F, Geological Survey of Canada Paper 88-1F, pp. 1-13 for a description of box-and-whisker plots.
## Make test data available data(kola.c) attach(kola.c) ## Display a simple box-and-whisker plot for measured variables bwplots.by.var(cbind(Co,Cu,Ni)) ## Display a more appropriately labelled and scaled box-and-whisker plot bwplots.by.var(cbind(Co,Cu,Ni), log = TRUE, ylab = "Levels (mg/kg) in <2 mm Kola C-horizon soil") ## Detach test data detach(kola.c) ## Make test data available data(ms.data1) attach(ms.data1) ## Display variables in a data frame extending the whiskers to the ## 2nd and 98th percentiles of the data, remembering to omit the ## sample IDs bwplots.by.var(ms.data1[, -1], log = TRUE, wend = 0.02) ## Detach test data detach(ms.data1)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.