matrix_freq {surveyexplorer}R Documentation

Matrix Frequency Plot

Description

Generate a grouped bar chart displaying the frequency distribution of responses for a categorical variable. The function supports optional subgrouping of data using the group_by variable, exclusion of specific subgroups with 'subgroups_to_exclude,' and data weighting with the 'weights' parameter. Users can also choose to exclude NA values from the questions prior to analysis using the 'na.rm' parameter.

Usage

matrix_freq(
  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 question before analysis.

Value

A ggplot2 object representing a grouped bar chart displaying the frequency distribution of responses for the specified categorical variable. The chart supports grouping, weighting, and exclusion of subgroups.

See Also

Other matrix questions: matrix_likert(), matrix_mean(), matrix_table()

Examples

 #Array question (1-5)
  matrix_freq(berlinbears, dplyr::starts_with('p_'))

  #remove NA category
  matrix_freq(berlinbears, dplyr::starts_with('p_'), na.rm = TRUE)

  #Use `group_by` to partition the question into several groups
  matrix_freq(berlinbears, dplyr::starts_with('p_'), group_by = species,
  subgroups_to_exclude = c('panda bear', NA ), na.rm = TRUE)

  #Categorical input
  matrix_freq(berlinbears, dplyr::starts_with('c_'), group_by = is_parent, na.rm = TRUE)




[Package surveyexplorer version 0.1.0 Index]