| bixplot | R Documentation |
Draws a bixplot for one or more numeric variables. A bixplot extends the violin plot and boxplot by automatically testing each variable for unimodality (via Hartigan's dip test) and, when multimodality is detected, fitting a constrained k-medoids clustering to identify and separately display the modes. Each variable is rendered as a filled density body, a box-and-whisker summary, and a rug of individual data values. The rug can optionally be colored by an external numeric or factor variable. Input can be provided as vectors, a data frame, a matrix, a list of vectors, or a formula.
bixplot(...,
names = NA,
add = FALSE,
at = NULL,
horizontal = FALSE,
col = "gray60", bodyCol = NULL,
bodyOpaque = 0.5,
bodyW = 0.80,
bodysize = "area_from_count",
modeCol = c("cadetblue3", "hotpink2",
"lawngreen", "orange", "cyan3",
"coral2", "gray60", "darkgoldenrod2",
"slateblue2", "brown2", "khaki3"),
curveCol = "black",
curveLwd = 1,
border = "black", boxCol = NULL,
boxOpaque = 0.5,
boxW = 0.32,
boxLwd = 2,
makewhiskers = TRUE,
innerwhiskers = TRUE,
rugCol = "black",
rugoutCol = par("fg"),
rugNumeric = NULL,
rugNumericColors = c("blue", "green"),
colorbarW = 0.12,
rugFactor = NULL,
rugFactorColors = c("red", "blue", "forestgreen"),
rugLwd = par("lwd"),
rugoutLwd = 2 * rugLwd,
rugOpaque = 0.4,
jittering = TRUE,
jitteramount = NULL,
rugW = 0.12,
stickCol = "black",
stickLwd = 2,
boxwex = 1,
width = NULL,
side = "no",
tick = TRUE,
diplevel = 0.01,
minN = 15,
kmax = NULL,
bigN = 500,
clusMinN = 3,
bw = "SJ-dpi",
kernel = "gaussian",
cut = 3,
cutmin = -Inf,
cutmax = Inf,
xlim = NULL,
ylim = NULL,
cex.axis = 1,
main = "bixplot",
cex.main = 1, line.main = 1,
cex.colorbar = 1,
xlab = "",
ylab = "",
cex.lab = 1, line.lab = 2.2,
xaxs = "r", yaxs = "r", las = 1,
ann = !add,
plot = TRUE,
log = NULL)
... |
one or more numeric vectors to plot, or a single data
frame or matrix whose columns are plotted, or a single list of
numeric vectors (which may have different lengths), or a formula
such as |
names |
character vector of group labels printed next to each
variable. If |
add |
logical. If |
at |
numeric vector specifying the axis positions at which the
bixplots are drawn, particularly useful when |
horizontal |
logical. If |
col |
color(s) for the density body of variables deemed
unimodal. Can be a single color or a vector recycled to length
|
bodyCol |
if not |
bodyOpaque |
numeric between 0 (transparent) and 1 (opaque)
controlling the opacity of the filled density body. Defaults to
|
bodyW |
numeric vector (recycled to length |
bodysize |
character string determining how the density bodies
of individual modes within the same variable are sized relative to
each other. One of |
modeCol |
color(s) of the density bodies for variables with
more than one detected mode (cluster). Cycled across all modes of
all multimodal variables. If |
curveCol |
color(s) of the density curve boundary drawn around
each body. Can be a single color or a vector recycled to length
|
curveLwd |
single number giving the line width of the density curve. |
border |
color(s) of the box and whiskers. Can be a single
color or a vector recycled to length |
boxCol |
if not |
boxOpaque |
numeric between 0 and 1 controlling the opacity of
the lines making up the boxplot. Defaults to |
boxW |
numeric vector (recycled to length |
boxLwd |
single number giving the line width of the box and whiskers. |
makewhiskers |
logical. If |
innerwhiskers |
logical. Relevant only when a variable has more
than one mode. If |
rugCol |
color(s) of the rug tick marks for each variable.
Can be a single color or a vector recycled to length |
rugoutCol |
color(s) of the portion of rug lines that extends
outside the density body. If |
rugNumeric |
optional numeric vector of the same length as each
|
rugNumericColors |
vector of two or three colors passed to
|
colorbarW |
width of the color bar legend for |
rugFactor |
optional factor variable of the same length as each
|
rugFactorColors |
character vector of colors for the levels of
|
rugLwd |
single number giving the line width of the rug marks.
Defaults to |
rugoutLwd |
single number giving the line width of the part of
rug lines outside the density body. Defaults to
|
rugOpaque |
numeric between 0 and 1 controlling the opacity of
the rug marks. Defaults to |
jittering |
logical. If |
jitteramount |
amount of jittering passed to
|
rugW |
numeric vector (recycled to length |
stickCol |
color(s) of the vertical or horizontal "stick" drawn
when |
stickLwd |
single number giving the line width of the stick.
Set to zero to suppress the stick. Defaults to |
boxwex |
scale factor applied uniformly to the widths of the
body, box and rug across all bixplots. [Argument from
|
width |
optional numeric vector of length |
side |
character string specifying which side of the variable
axis the body, box and rug are drawn on. One of |
tick |
logical indicating whether tick marks are drawn on the
group-label axis. Only has an effect when |
diplevel |
significance level for Hartigan's dip test for
unimodality. A cluster search is only performed for variables
whose dip test p-value is at most |
minN |
minimum number of observations required per potential
cluster. Defaults to |
kmax |
maximum number of clusters to consider. Internally
capped at 5. If |
bigN |
when a variable has more than |
clusMinN |
minimum number of unique values that each cluster
must contain. The constrained clustering enforces this bound.
Defaults to |
bw |
bandwidth for |
kernel |
kernel for |
cut |
the density is computed from
|
cutmin |
if finite, the density of every variable and mode is
truncated to begin no lower than |
cutmax |
if finite, the density of every variable and mode is
truncated to end no higher than |
xlim |
numeric vector of length 2 giving the limits of the
group axis (whether |
ylim |
numeric vector of length 2 giving the limits of the
numeric value axis (whether |
cex.axis |
character expansion factor for axis tick labels. |
main |
title of the plot. Defaults to |
cex.main |
character expansion factor for the title. |
line.main |
margin line for the title (passed to
|
cex.colorbar |
character expansion factor for the color bar
axis labels when |
xlab |
label for the horizontal axis. Defaults to |
ylab |
label for the vertical axis. Defaults to |
cex.lab |
character expansion factor for axis labels. |
line.lab |
margin line for axis labels. Defaults to
|
xaxs |
axis interval calculation style for the x-axis
(see |
yaxs |
axis interval calculation style for the y-axis.
Defaults to |
las |
orientation of axis tick labels
(see |
ann |
logical indicating whether the plot should be annotated
with |
plot |
if |
log |
this argument from |
For each variable, bixplot proceeds as follows. Hartigan's
dip test is applied to test for unimodality; if the p-value exceeds
diplevel, or if the sample is too small (n < 2 * minN),
the variable is treated as unimodal (k = 1). Otherwise,
constrained k-medoids clustering (via pamc1d) is fitted
for k = 2, ..., kmax clusters, and the best k is
selected by the highest mean silhouette width (computed via
silhouette). If no k > 1 yields a
positive mean silhouette width, the variable is treated as unimodal.
A single global bandwidth is computed once per variable and reused
for the density of every mode, ensuring that density bodies are
comparable across modes. Mode sizes are scaled according to
bodysize.
When side = "both", adjacent variables are paired and plotted
as half-bixplots on opposite sides of shared axes, and axis labels
are combined automatically from the names of each pair.
The arguments rugNumeric and rugFactor require all
variables to have the same number of observations. They cannot be
specified simultaneously.
A list returned invisibly when plot = TRUE (or visibly when
plot = FALSE), containing:
call |
the matched call. |
p |
the number of variables plotted. |
<name_1>, <name_2>, ... |
one list entry per variable,
named after the variable. For a unimodal variable the list
contains |
P.J. Rousseeuw
Montalcini, C., Rousseeuw, P.J. (2025). The bixplot: A variation on the boxplot suited for bimodal data, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.48550/arXiv.2510.09276")} (open access).
pamc1d,
pam,
silhouette,
dip.test,
density,
boxplot
set.seed(1)
# A unimodal and a clearly bimodal variable
x1 <- rnorm(100)
x2 <- c(rnorm(60, mean = -3), rnorm(60, mean = 3))
bixplot(x1, x2, names = c("unimodal", "bimodal"),
main = "Basic bixplot example")
# Formula interface, coloring rug by a factor
n <- 150
grp <- factor(rep(c("A", "B", "C"), each = 50))
y <- c(rnorm(50, 0), rnorm(50, 4), rnorm(50, 8))
bixplot(y ~ grp, main = "Formula interface")
# Horizontal layout with an external numeric rug variable
set.seed(42)
vals <- c(rnorm(80, mean = -2), rnorm(80, mean = 2))
covariate <- runif(160)
bixplot(vals, horizontal = TRUE,
rugNumeric = covariate,
rugNumericColors = c("purple", "yellow"),
main = "Horizontal bixplot with numeric rug")
# Side-by-side ("both") half-bixplots
bixplot(x1, x2, side = "both",
names = c("unimodal vs bimodal"),
main = "side = both")
# For more examples, we refer to the vignette:
## Not run:
vignette("bixplot_examples")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.