bxplot: Plot a Horizontal Boxplot or Box-and-Whisker Plot

Description Usage Arguments Details Note Author(s) References See Also Examples

View source: R/bxplot.R


Plots a single horizontal boxplot as part of the multi-panel display provided by function shape, the default is a Tukey boxplot, alternately a box-and-whisker plot (Garrett, 1988) may be displayed. Optionally the x-axis may be scaled logarithmically (base 10).


bxplot(xx, xlab = deparse(substitute(xx)), log = FALSE,
	ifbw = FALSE, wend = 0.05, xlim = NULL, main = "", ifn = TRUE, 
	colr = 8, cex = 1, ...)



name of the variable to be plotted.


by default the character string for xx is used for the x-axis title. An alternate title can be displayed with xlab = "text string", see Examples.


to display the data with logarithmic (x-axis) scaling, set log = TRUE.


the default is to plot a horizontal Tukey boxplot, if a box-and-whisker plot is required set ifbw = TRUE.


if ifbw = TRUE the locations of the whisker-ends have to be defined. By default these are at the 5th and 95th percentiles of the data. Setting wend = 0.02 plots the whisker ends at the 2nd and 98th percentiles.


when used in the shape function, xlim is determined by gx.hist and used to ensure all four panels in shape have the same x-axis scaling. However when used stand-alone the limits may be user-defined by setting xlim, see Note below.


when used stand-alone a title may be added optionally above the plot by setting main, e.g., main = "Kola Project, 1995".


an internal ‘switch’ set FALSE to suppress the addition of the sample size to the plot.


by default the box is infilled in grey, colr = 8. If no infill is required, set colr = 0. See display.lty for the range of available colours.


by default the size of the text for data set size, N, is set to 80%, i.e. cex = 0.8, and may be changed if required.


further arguments to be passed to methods. For example, the size of the axis scale annotation can be change by setting cex.axis, the size of the axis titles by setting cex.lab, and the size of the plot title by setting cex.main. For example, if it is required to make the plot title smaller, add cex.main = 0.9 to reduce the font size by 10%.


The function can be used stand-alone, but as Tukey boxplots and box-and-whisker plots are usually used to compare the distributions of data subsets the functions tbplots (Tukey boxplots) and bwplots (box-and-whisker plots) are required for that purpose.

When the boxplot is displayed on a logarithmically scaled x-axis, the data are log transformed prior to the computation of the positions of the fences used in the Tukey boxplot to identify near and far outliers, plotted as plusses and circles, respectively.

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 minimum and maximum are plotted, only the median and box representing the span of the middle 50 percent of the data are displayed.


Any less than detection limit values represented by negative values, or zeros or numeric codes representing blanks in the data, must be removed prior to executing this function, see ltdl.fix.df.

Any NAs in the data vector are removed prior to displaying the plot.

If the default selection for xlim is inappropriate it can be set, e.g., xlim = c(0, 200) or c(2, 200), the latter being appropriate for a logarithmically scaled plot, i.e. log = TRUE. If the defined limits lie within the observed data range a truncated plot will be displayed. If this occurs the number of data points omitted is displayed below the total number of observations.

If it is desired to prepare a display of data falling within a defined part of the actual data range, then either a data subset can be prepared externally using the appropriate R syntax, or xx may be defined in the function call as, for example, Cu[Cu < some.value] which would remove the influence of one or more outliers having values greater than some.value. In this case the number of data values displayed will be the number that are <some.value.


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.

See Also

shape, display.lty, ltdl.fix.df, remove.na


## Make test data available

## Display a simple boxplot

## Display a more appropriately labelled and scaled boxplot
bxplot(Cu, xlab = "Cu (mg/kg) in <2 mm Kola O-horizon soil", log = TRUE)

## Display a box-and-whisker plot with whiskers ending at the 2nd and
## 98th percentiles
bxplot(Cu, xlab = "Cu (mg/kg) in <2 mm Kola O-horizon soil", ifbw = TRUE, 
	wend = 0.02, log = TRUE)

## Detach test data

rgr documentation built on May 29, 2017, 7:16 p.m.

Search within the rgr package
Search all R packages, documentation and source code