matrix_mean {surveyexplorer} | R Documentation |
Matrix Mean Plot
Description
This function creates a likert-style plot showing means and standard errors
for a specified numeric variable, question
. Optionally, the plot can be
grouped by another variable, group_by
, and subgroups can be excluded. If
survey weights are provided, the counts are adjusted accordingly. The plot is
flipped for better readability in likert-style format.
Usage
matrix_mean(
dataset,
question,
group_by = NULL,
subgroups_to_exclude = NULL,
weights = NULL,
na.rm = FALSE
)
Arguments
dataset |
The input dataframe (or tibble) of survey questions |
question |
The columns that contain each of the response options for a question, can be selected by using tidyselect semanatics or providing a vector of column names or numbers |
group_by |
Optional variable to group the analysis. If provided, the frequencies and counts will be calculated within each subgroup. |
subgroups_to_exclude |
Optional vector specifying subgroups to exclude from the analysis. |
weights |
Optional variable containing survey weights. If provided, frequencies and counts will be weighted accordingly. |
na.rm |
Logical indicating whether to remove NA values from |
Value
A likert-style ggplot displaying means and standard errors. The plot is flipped for better readability, and if grouping is specified, different colors represent distinct subgroups.
See Also
Other matrix questions:
matrix_freq()
,
matrix_likert()
,
matrix_table()
Examples
#basic plot
matrix_mean(berlinbears, dplyr::starts_with('p_'))
#with grouping and weights
matrix_mean(berlinbears, dplyr::starts_with('p_'), group_by = species,
subgroups_to_exclude = 'panda bear', weights = weights, na.rm = TRUE )