Generate Box-Whisker Plots
plotBoxWhisker.RdProduces box-and-whisker plots for visualizing the distribution of data. For more details and examples, see the vignettes:
vignette("Box-Whisker Plots", package = "ospsuite.plots")vignette("ospsuite.plots", package = "ospsuite.plots")
Usage
plotBoxWhisker(
data,
mapping,
metaData = NULL,
plotObject = NULL,
percentiles = getOspsuite.plots.option(optionKey = OptionKeys$Percentiles),
yscale = AxisScales$linear,
yscale.args = list(),
xscale = "auto",
xscale.args = list(),
statFun = NULL,
outliers = FALSE,
statFunOutlier = NULL,
geomBoxplotAttributes = getDefaultGeomAttributes("Boxplot"),
geomPointAttributes = getDefaultGeomAttributes("Boxplot"),
residualScale = ResidualScales$log
)Arguments
- data
A
data.framecontaining the data to aggregate.- mapping
A list of aesthetic mappings to use for the plot.
- metaData
A named list of information about
datasuch as thedimensionandunitof its variables.- plotObject
An optional
ggplotobject on which to add the plot layers- percentiles
A numeric vector with percentiles used for the box whiskers and boxes, e.g., c(0.05, 0.25, 0.5, 0.75, 0.95). Default defined by
ospsuite.plotsoption.- yscale
either 'linear' then
ggplot2::scale_y_continuous()or 'log' thenggplot2::scale_y_log10()is used- yscale.args
list of arguments passed to
ggplot2::scale_y_continuous()orggplot2::scale_y_log10()- xscale
Either 'linear', 'log', 'discrete', or 'auto' (default). Auto selects linear for continuous data and discrete for categorical data.
- xscale.args
A list of arguments passed to
ggplot2::scale_x_continuous(),ggplot2::scale_x_log10(), orggplot2::scale_x_discrete().- statFun
(default NULL) A function to calculate whiskers and box ranges, which overwrites the
percentilesvariable if provided.- outliers
Logical indicating whether outliers should be included in the boxplot. Outliers are flagged when outside the range from the "25th" percentile - 1.5 x IQR to the "75th" percentile + 1.5 x IQR, as suggested by McGill et al.
- statFunOutlier
(default NULL) A function to calculate outliers, which overwrites the default calculation if provided.
- geomBoxplotAttributes
A
listof arguments passed to thegeom_boxplotcall.- geomPointAttributes
A
listof arguments passed to theggplot2::geom_pointcall.- residualScale
Either "linear", "log", or "ratio" scale for residuals.
References
McGill, R., Tukey, J. W., & Larsen, W. A. (1978). Variations of box plots. The American Statistician, 32(1), 12-16.
See also
Other plot functions:
plotForest(),
plotHistogram(),
plotPredVsObs(),
plotQQ(),
plotRangeDistribution(),
plotRatioVsCov(),
plotResVsCov(),
plotTimeProfile(),
plotYVsX()
Examples
if (FALSE) { # \dontrun{
# Basic box-whisker plot
plotBoxWhisker(
data = myData,
mapping = aes(x = group, y = value)
)
# Box-whisker plot with custom percentiles
plotBoxWhisker(
data = myData,
mapping = aes(x = treatment, y = response),
percentiles = c(0.1, 0.25, 0.5, 0.75, 0.9)
)
# Box-whisker plot with custom stat function
customStatFun <- function(x) {
return(quantile(x, probs = c(0.05, 0.25, 0.5, 0.75, 0.95), na.rm = TRUE))
}
plotBoxWhisker(
data = myData,
mapping = aes(x = dose_group, y = concentration),
statFun = customStatFun,
outliers = TRUE
)
} # }