makeme {saros} | R Documentation |
Embed Interactive Plot of Various Kinds Using Tidyselect Syntax
Description
This function allows embedding of interactive or static plots based on various types of data using tidyselect syntax for variable selection.
Usage
makeme(
data,
dep = tidyselect::everything(),
indep = NULL,
type = c("cat_plot_html", "int_plot_html", "cat_table_html", "int_table_html",
"sigtest_table_html", "cat_prop_plot_docx", "cat_freq_plot_docx", "int_plot_docx"),
...,
require_common_categories = TRUE,
crowd = c("all"),
mesos_var = NULL,
mesos_group = NULL,
simplify_output = TRUE,
hide_for_crowd_if_all_na = TRUE,
hide_for_crowd_if_valid_n_below = 0,
hide_for_crowd_if_category_k_below = 2,
hide_for_crowd_if_category_n_below = 0,
hide_for_crowd_if_cell_n_below = 0,
hide_for_all_crowds_if_hidden_for_crowd = NULL,
hide_indep_cat_for_all_crowds_if_hidden_for_crowd = FALSE,
add_n_to_dep_label = FALSE,
add_n_to_indep_label = FALSE,
add_n_to_label = FALSE,
add_n_to_category = FALSE,
totals = FALSE,
categories_treated_as_na = NULL,
label_separator = " - ",
error_on_duplicates = TRUE,
showNA = c("ifany", "always", "never"),
data_label = c("percentage_bare", "percentage", "proportion", "count"),
html_interactive = TRUE,
hide_axis_text_if_single_variable = TRUE,
hide_label_if_prop_below = 0.01,
inverse = FALSE,
vertical = FALSE,
digits = 0,
data_label_decimal_symbol = ".",
x_axis_label_width = 25,
strip_width = 25,
sort_by = ".upper",
descend = TRUE,
labels_always_at_top = NULL,
labels_always_at_bottom = NULL,
table_wide = TRUE,
table_main_question_as_header = FALSE,
n_categories_limit = 12,
translations = list(last_sep = " and ", table_heading_N = "Total (N)",
table_heading_data_label = "%", add_n_to_dep_label_prefix = " (N = ",
add_n_to_dep_label_suffix = ")", add_n_to_indep_label_prefix = " (N = ",
add_n_to_indep_label_suffix = ")", add_n_to_label_prefix = " (N = ",
add_n_to_label_suffix = ")", add_n_to_category_prefix = " (N = [",
add_n_to_category_infix = ",", add_n_to_category_suffix = "])", by_total =
"Everyone", sigtest_variable_header_1 = "Var 1", sigtest_variable_header_2 = "Var 2",
crowd_all = "All",
crowd_target = "Target", crowd_others = "Others"),
plot_height = 15,
colour_palette = NULL,
colour_2nd_binary_cat = "#ffffff",
colour_na = "grey",
label_font_size = 6,
main_font_size = 6,
strip_font_size = 6,
legend_font_size = 6,
font_family = "sans",
path = NULL,
docx_template = NULL
)
Arguments
data |
Your data.frame/tibble or srvyr-object (experimental)
The data to be used for plotting. |
dep , indep |
Variable selections < Columns in |
type |
Kind of output
For a list of registered types in your session, use |
... |
Dynamic dots Arguments forwarded to the corresponding functions that create the elements. |
require_common_categories |
Check common categories
Whether to check if all items share common categories. |
crowd |
Which group(s) to display results for
Choose whether to produce results for target (mesos) group, others, all, or combinations of these. |
mesos_var |
Variable in
Column name in data indicating the groups for which mesos reports will be produced. |
mesos_group |
String, target group. |
simplify_output |
If TRUE, a list output with a single output element will return the element itself, whereas list with multiple elements will return the list. |
hide_for_crowd_if_all_na |
Hide variable from output if containing all NA
Whether to remove all variables (in particular useful for mesos) if all values are NA |
hide_for_crowd_if_valid_n_below |
Hide variable if variable has < n observations
Whether to hide a variable for a crowd if variable contains fewer than n observations (always ignoring NA). |
hide_for_crowd_if_category_k_below |
Hide variable if < k categories
Whether to hide a variable for a crowd if variable contains fewer than k used categories (always ignoring NA).
Defaults to |
hide_for_crowd_if_category_n_below |
Hide variable if having a category with < n observations
Whether to hide a variable for a crowd if variable contains a category with less than n observations (ignoring NA) Cells with a 0 count is not considered as these are usually not a problem for anonymity. |
hide_for_crowd_if_cell_n_below |
Hide variable if having a cell with < n
Whether to hide a variable for a crowd if the combination of dep-indep results in a cell with less than n observations (ignoring NA). Cells with a 0 count is not considered as these are usually not a problem for anonymity. |
Conditional hiding
Select one of the
will hide variables from both target and others-outputs if all are NA in the target-group. | |
Conditionally hide independent categories
If | |
add_n_to_dep_label , add_n_to_indep_label |
Add N= to the variable label
For some plots and tables it is useful to attach the |
add_n_to_label |
Add N= to the variable label of both dep and indep
For some plots and tables it is useful to attach the |
add_n_to_category |
Add N= to the category
For some plots and tables it is useful to attach the |
totals |
Include totals
Whether to include totals in the output. |
categories_treated_as_na |
NA categories
Categories that should be treated as NA. |
label_separator |
How to separate main question from sub-question
Separator for main question from sub-question. |
error_on_duplicates |
Error or warn on duplicate labels
Whether to abort ( |
showNA |
Show NA categories
Choose whether to show NA categories in the results. |
data_label |
Data label
One of "proportion", "percentage", "percentage_bare", "count", "mean", or "median". |
html_interactive |
Toggle interactive plot
Whether the plot is to be interactive (ggiraph) or static (ggplot2). |
hide_axis_text_if_single_variable |
Hide y-axis text if just a single variable
Whether to hide text on the y-axis label if just a single variable. |
hide_label_if_prop_below |
Hide label threshold
Whether to hide label if below this value. |
inverse |
Flag to swap x-axis and faceting
If TRUE, swaps x-axis and faceting. |
vertical |
Display plot vertically
If TRUE, display plot vertically. |
digits |
Decimal places
Number of decimal places. |
data_label_decimal_symbol |
Decimal symbol
Decimal marker, some might prefer a comma ',' or something else entirely. |
x_axis_label_width , strip_width |
Label width of x-axis and strip texts in plots
Width of the labels used for the categorical column names in x-axis texts and strip texts. |
sort_by |
What to sort output by
Sort output (and collapse if requested). When using
|
descend |
Sorting order
Reverse sorting of |
labels_always_at_top , labels_always_at_bottom |
Top/bottom variables
Column names in |
table_wide |
Pivot table wider
Whether to pivot table wider. |
table_main_question_as_header |
Table main question as header
Whether to include the main question as a header in the table. |
n_categories_limit |
Limit for cat_table_ wide format
If there are more than this number of categories in the categorical variable, cat_table_* will have a long format instead of wide format. |
translations |
Localize your output
A list of translations where the name is the code and the value is the translation. See the examples. |
plot_height |
DOCX-setting
DOCX plots need a height, which currently cannot be set easily with a Quarto chunk option. |
colour_palette |
Colour palette
Must contain at least the number of unique values (including missing) in the data set. |
colour_2nd_binary_cat |
Colour for second binary category
Colour for the second category in binary variables. Often useful to hide this. |
colour_na |
Colour for NA category
Colour as a single string for NA values, if showNA is "ifany" or "always". |
main_font_size , label_font_size , strip_font_size , legend_font_size |
Font sizes
ONLY FOR DOCX-OUTPUT. Other output is adjusted using e.g. ggplot2::theme() or set with a global theme (ggplot2::theme_set()). Font sizes for general text (6), data label text (3), strip text (6) and legend text (6). |
font_family |
Font family
Word font family. See officer::fp_text. |
path |
Output path for DOCX
Path to save docx-output. |
docx_template |
Filename or rdocx object
Can be either a valid character path to a reference Word file, or an existing rdocx-object in memory. |
Value
ggplot-object, optionally an extended ggplot object with ggiraph features.
Examples
makeme(
data = ex_survey,
dep = b_1:b_3
)
makeme(
data = ex_survey,
dep = b_1, indep = x1_sex
)
makeme(
data = ex_survey,
dep = b_1:b_3, indep = c(x1_sex, x2_human),
type = "sigtest_table_html"
)
makeme(
data = ex_survey,
dep = b_1, indep = x1_sex,
type = "cat_prop_plot_docx"
)
makeme(
data = ex_survey,
dep = p_1:p_4, indep = x2_human,
type = "cat_table_html"
)
makeme(
data = ex_survey,
dep = b_1:b_3,
crowd = c("target", "others", "all"),
mesos_var = "f_uni",
mesos_group = "Uni of A"
)