Summarize a survey dataset for use in tables and graphs
summarize_cat_cat_data(
data,
dep = colnames(data),
indep = NULL,
...,
showNA = c("ifany", "always", "never"),
totals = FALSE,
sort_by = ".upper",
sort_dep_by = NULL,
sort_indep_by = ".factor_order",
data_label = c("percentage_bare", "percentage", "proportion", "count", "mean",
"median"),
digits = 0,
add_n_to_dep_label = FALSE,
add_n_to_indep_label = FALSE,
add_n_to_label = FALSE,
add_n_to_category = FALSE,
hide_label_if_prop_below = 0.01,
data_label_decimal_symbol = ".",
categories_treated_as_na = NULL,
label_separator = NULL,
descend = FALSE,
descend_indep = FALSE,
labels_always_at_bottom = NULL,
labels_always_at_top = NULL,
translations = list(),
call = rlang::caller_env()
)Dataset with the columns: .variable_name, .variable_label, .category,
.count, .count_se, .count_per_dep, .count_per_indep_group, .proportion, .proportion_se,
.mean, .mean_se, .median, indep-variable(s), .data_label, .comb_categories, .sum_value,
.variable_label_prefix
Your data.frame/tibble or srvyr-object (experimental)
data.frame // required
The data to be used for plotting.
Variable selections
<tidyselect> // Default: NULL, meaning everything for dep, nothing for indep.
Columns in data. dep is compulsory.
Dynamic dots
Arguments forwarded to the corresponding functions that create the elements.
Show NA categories
vector<character> // default: c("ifany", "always", "never") (optional)
Choose whether to show NA categories in the results.
Include totals
scalar<logical> // default: FALSE (optional)
Whether to include totals in the output.
What to sort output by (legacy)
vector<character> // default: NULL (optional)
DEPRECATED: Use sort_dep_by and sort_indep_by instead for clearer control.
When specified, this parameter will be used for both dependent and independent sorting.
If NULL (default), dependent variables will be sorted by .variable_position.
Uses .variable_position for dependent variables, no sorting for independent.
The proportion for the highest category available in the variable.
The sum of the proportions for the categories above the middle category.
The sum of the proportions for the categories including and above the middle category.
The sum of the proportions for the categories including and below the middle category.
The sum of the proportions for the categories below the middle category.
The proportions for the lowest category available in the variable.
Sort by the variable labels.
Sort by the variable names.
Sort by the variable position in the supplied data frame.
The groups of the by argument.
Character vector of category labels to sum together.
What to sort dependent variables by
vector<character> // default: ".variable_position" (optional)
Sort dependent variables in output. When using indep-argument,
sorting differs between ordered factors and unordered factors: Ordering
of ordered factors is always respected in output (their levels define
the base order). Unordered factors will be reordered by sort_dep_by.
Sort by variable position in the supplied data frame (default).
Sort by the variable labels.
Sort by the variable names.
The proportion for the highest category available in the variable.
The sum of the proportions for the categories above the middle category.
The sum of the proportions for the categories including and above the middle category.
The sum of the proportions for the categories including and below the middle category.
The sum of the proportions for the categories below the middle category.
The proportions for the lowest category available in the variable.
What to sort independent variable categories by
vector<character> // default: ".factor_order" (optional)
Sort independent variable categories in output. When ".factor_order",
preserves the original factor level order for the independent variable.
Passing NULL is accepted and treated as ".factor_order".
No sorting - preserves original factor level order (default).
The proportion for the highest category available.
The sum of the proportions for the categories above the middle category.
The sum of the proportions for the categories including and above the middle category.
The sum of the proportions for the categories including and below the middle category.
The sum of the proportions for the categories below the middle category.
The proportions for the lowest category available.
Character vector of category labels to sum together.
Data label
scalar<character> // default: "proportion" (optional)
One of "proportion", "percentage", "percentage_bare", "count", "mean", or "median".
Decimal places
scalar<integer> // default: 0L (optional)
Number of decimal places.
Add N= to the variable label
scalar<logical> // default: FALSE (optional)
For some plots and tables it is useful to attach the "N=" to the end of the label of
the dependent and/or independent variable.
Whether it is N or N_valid depends on your showNA-setting. See also
translations$add_n_to_dep_label_prefix,
translations$add_n_to_dep_label_suffix,
translations$add_n_to_indep_label_prefix,
translations$add_n_to_indep_label_suffix.
Add N= to the variable label of both dep and indep
scalar<logical> // default: FALSE (optional)
For some plots and tables it is useful to attach the "N=" to the end of the label.
Whether it is N or N_valid depends on your showNA-setting. See also
translations$add_n_to_label_prefix and
translations$add_n_to_label_suffix.
Add N= to the category
scalar<logical> // default: FALSE (optional)
For some plots and tables it is useful to attach the "N=" to the end of the category.
This will likely produce a range across the variables, hence an infix (comma)
between the minimum and maximum can be specified.
Whether it is N or N_valid depends on your showNA-setting. See also
translations$add_n_to_category_prefix,
translations$add_n_to_category_infix, and
translations$add_n_to_category_suffix.
Hide label threshold
scalar<numeric> // default: NULL (optional)
Whether to hide label if below this value.
Decimal symbol
scalar<character> // default: "." (optional)
Decimal marker, some might prefer a comma ',' or something else entirely.
NA categories
vector<character> // default: NULL (optional)
Categories that should be treated as NA.
How to separate main question from sub-question
scalar<character> // default: NULL (optional)
Separator for main question from sub-question.
Sorting order
scalar<logical> // default: FALSE (optional)
Reverse sorting of sort_by in figures and tables. Works with both
ordered and unordered factors - for ordered factors, it reverses the
display order while preserving the inherent level ordering.
See arrange_section_by for sorting of report sections.
Sorting order for independent variables
scalar<logical> // default: FALSE (optional)
Reverse sorting of sort_indep_by in figures and tables. Works with both
ordered and unordered factors - for ordered factors, it reverses the
display order while preserving the inherent level ordering.
See arrange_section_by for sorting of report sections.
Top/bottom variables
vector<character> // default: NULL (optional)
Column names in data that should always be placed at the top or bottom of figures/tables.
Localize your output
list<character>
A list of translations where the name is the code and the value is the translation. See the examples.
Internal call
obj:<call> // Default: rlang::caller_env() (optional)
Both the absolute and relative folderpaths are required, as strings.