Plots a set of categorical variables that share the same response categories
(e.g. a battery of Likert items) as a single chart, drawing one stacked
horizontal bar per item. Internally the items are reshaped to long format and
handed to the same machinery as stem_barplot(), with the item taking the
role of the group.
Usage
stem_battery(
data,
items,
weight = NULL,
order_by = NULL,
item_label = TRUE,
palette = "div1",
direction = 1,
labels = TRUE,
label_accuracy = 1,
label_suffix = "",
label_hide = 0.05,
label_color = "black",
label_bicolor = TRUE
)Arguments
- data
Data frame holding the item (and group) variables.
- items
Items to plot. Supports tidyselect helpers (e.g.
dplyr::starts_with()).- weight
Optional survey weights.
- order_by
Optional vector of response categories used to order the items, e.g.
c("Definitely Agree", "Rather Agree")orders items by their combined share of those two categories.- item_label
If
TRUE(default), item labels (the"label"attribute) are used instead of variable names. Falls back to names, with a warning, if any item lacks a label.- palette
Name of a Stem palette. See
stem_palette().- direction
Palette direction. Use
-1to reverse the colours.- labels
If
TRUE, prints a percentage label on each bar.- label_accuracy
Rounding accuracy of labels.
1gives whole numbers,0.1one decimal place.- label_suffix
Suffix appended to labels. Defaults to
"".- label_hide
Proportions below this threshold are left unlabelled. Defaults to
0.05when agroupis supplied (to keep small stacked segments unlabelled) and0otherwise.- label_color
Colour of the segment labels in grouped (stacked) plots. Defaults to
"black".- label_bicolor
If
TRUE(default), in grouped (stacked) plots the labels of the two side (extreme) item categories are drawn in white, while all other labels uselabel_color. Set toFALSEto colour every label withlabel_color.