Combines density plots and horizontal boxplots for a numeric variable, optionally grouped by a categorical variable. The density plot shows the distribution shape, while the boxplot summarizes key statistics such as median, spread, and outliers.
Usage
plotDensBox(x, ...)
# Default S3 method
plotDensBox(
x,
g = NULL,
main = "",
xlab = "",
ylab = "",
xlim = NULL,
layout_heights = c(2, 1.4),
col = NULL,
grid = TRUE,
densArgs = TRUE,
boxArgs = TRUE,
stamp = NULL,
...
)
# S3 method for class 'formula'
plotDensBox(
formula,
data,
subset,
na.action = na.omit,
main = "",
xlab = "",
ylab = "",
xlim = NULL,
layout_heights = c(2, 1.4),
col = NULL,
grid = TRUE,
densArgs = TRUE,
boxArgs = TRUE,
stamp = NULL,
...
)Arguments
- x
numeric vector, or a formula of the form
x ~ g.- ...
further graphical parameters passed to
graphics::par()via the internal framework.- g
optional grouping variable (ignored if a formula is used).
- main
main title of the plot.
- xlab
label for the x-axis.
- ylab
label for the y-axis.
- xlim
numeric vector of length 2 specifying the x-axis limits.
- layout_heights
numeric vector of length 2 specifying the relative heights of the density plot (top) and boxplot (bottom).
- col
vector of colors. If
NULL, a palette is generated.- grid
controls drawing of the background grid. Can be:
TRUE: draw grid with default settingsFALSE,NULL,NA: suppress grida named list: arguments passed to
graphics::grid()
- densArgs
controls density estimation via
stats::density(). Can be:TRUE: use default density settingsFALSE,NULL,NA: suppress densitiesa named list: additional arguments passed to
stats::density()
- boxArgs
controls drawing of boxplots via
graphics::boxplot(). Can be:TRUE: use default boxplot settingsFALSE,NULL,NA: suppress boxplotsa named list: additional arguments passed to
graphics::boxplot()
- stamp
optional annotation passed to the plotting framework.
- formula
A formula of the form
y ~ group.- data
an optional data frame containing variables in the formula.
- subset
optional expression indicating which observations to use.
- na.action
a function specifying how missing values are handled.
Details
The function arranges two plots vertically using layout():
a density plot on top and a horizontal boxplot below. When a grouping
variable is provided, densities and boxplots are drawn for each group.
Optional plot components are controlled using
bedrock::callIf() semantics:
TRUE: draw with defaultsFALSE: suppress componentnamed list: customize component arguments
See also
stats::density(),
graphics::boxplot(),
bedrock::callIf()
Other plot.univariate:
plotArea(),
plotBar(),
plotBox(),
plotCatDist(),
plotDens(),
plotDot(),
plotECDF(),
plotFdist(),
plotLines(),
plotQQ(),
plotViolin()
