Plots a set of "select all that apply" items, showing the share of respondents that picked each option. The items are reshaped to long format and their (possibly weighted) frequencies are rescaled by the number of items so that the bars express percentages of respondents rather than of responses.
Usage
stem_multiselect(
data,
items,
group = NULL,
weight = NULL,
palette = "div1",
direction = 1,
labels = TRUE,
label_accuracy = 1,
label_suffix = "",
label_hide = 0,
infreq_order = TRUE,
background = TRUE,
background_fill = "grey85",
background_alpha = 1
)Arguments
- data
Data frame holding the item (and group) variables.
- items
Items to plot. Supports tidyselect helpers (e.g.
dplyr::starts_with()).- group
Optional grouping variable. When supplied, one stacked horizontal bar is drawn per group category (with the item mapped to fill) and proportions are computed within each group.
- weight
Optional survey weights.
- 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.- infreq_order
If
TRUE(default), options are ordered by frequency.- background
If
TRUE(default, ungrouped plots only), draws a full-width background bar behind each option.- background_fill
Fill colour of the background bars.
- background_alpha
Opacity of the background bars.
Examples
if (FALSE) { # \dontrun{
stem_multiselect(trust, items = dplyr::starts_with("biggest_concern"))
stem_multiselect(trust, items = dplyr::starts_with("biggest_concern"), weight = W)
} # }