Extending the Default Behavior
Source:vignettes/extending_default_behavior.Rmd
extending_default_behavior.RmdGreetings and welcome to gvsu215!
I’ve tried to keep function names simple and required arguments to a minimum to help students focus on the statistical content rather than the R code. That being said, there are some more advanced features and capabilities built into the package that you as the instructor may take advantage of if you so choose.
Different R Markdown Export Formats
This package should be able to be used in any output format using R Markdown, including HTML1, PDF, and Word. If this is not the case, reach out to Dr. John Gabrosek or submit an issue on GitHub.
If using PDF output, you will want to make sure student R Markdown
files have the following in the YAML header which will allow the
compiler to use the xelatex engine. As such, you will avoid
messages printing out from every function call and you will be able to
see special characters such as
.
output:
pdf_document:
latex_engine: xelatex
If you are exporting to Word documents, it is recommended to name
your variables wisely (i.e., short but understandable). Sometimes, line
breaks in table headers can be a little funky with Word documents. All
static headers have forced line breaks that will break in between words;
however, if variable names are too long or if there are too many columns
in the table, the table will appear too squished and might add line
breaks in places that are not ideal. You may also wish to force a page
break for a table, which can be done by piping the table code into the
flextable::paginate() function.
Extra Function Arguments
Many functions in this package have extra arguments that aren’t necessary for basic function features but can allow for a little customization depending on your pedagogical approach and preferences, such as if you are focusing on data literacy or proper axis labeling. Each of the functions listed below have extra arguments, which are detailed after the function name.
-
tbl_1var(),tbl_corr(),tbl_num_sum()- The
digitsargument can be specified with an integer value for the number of digits to round to. Defaults to 3. - The
captionargument can be used to override the default caption. - The
with_propargument (defaults to “no”) can be set to “yes” to replace the percent column with the corresponding proportions. - The
na_rmargument can be used to NOT remove missing values from the table (note that these functions remove missing values by default)
- The
-
tbl_2var()- The
row_pctargument can be used to add in row percentages in each cell. - The
digitsargument can be specified with an integer value for the number of digits to round to. Defaults to 3. - The
captionargument can be used to override the default caption. - The
na_rmargument can be used to NOT remove missing values from the table (note that missing values are removed by default)
- The
-
tbl_pctile()- The
probsargument can be used to specify which percentiles are to be given. Simply pass in a vector of values between 0 and 1. - The
digitsargument can be specified with an integer value for the number of digits to round to. Defaults to 3. - The
captionargument can be used to override the default caption.
- The
-
plot_bar()- The
typeargument can be used to specify if a plot withpercents orcounts is desired. - The
fillargument can be used to choose a fill color (for a single variable plot). - The
layoutargument can be used to swap between side-by-side (sbs, the default) and stacked bar plots (stack). - The
orientargument can be used to flip the axis. Choose either “vertical” (the default) or “horizontal”. - The
dodgeargument can be used to create more rows on the x-axis labels. This can help if your labels are overlapping. Use an integer to tell how many row to create (more than 2 is not recommended for interpretability). - The
titleargument can be used to override the default title. - The
...is used for other labels on the plot, namely, the x- and y-axis labels.
- The
-
plot_box()- The
fillargument can be used to choose a fill color. - The
breaksargument can be used to specify x-axis breaks. Useseq(start, stop, jump). - The
orientargument can be used to flip the axis. Choose either “vertical” (the default) or “horizontal”. - The
titleargument can be used to override the default title. - The
...is used for other labels on the plot, namely, the x- and y-axis labels.
- The
-
plot_hist()- The
group_colsargument can be used with a grouped histogram to specify how many columns the faceted output should take up. - The
fillargument can be used to choose a fill color. - The
breakscan be used to specify how the x-axis labels should be broken. Useseq(_START_, _STOP_, _JUMP_). Accuracy is not guaranteed. - The
titleargument can be used to override the default title. - The
...is used for other labels on the plot, namely, the x- and y-axis labels.
- The
-
plot_scatter()- The
fillargument can be used to choose a fill color (for a non-grouped plot). - The
titleargument can be used to override the default title. - The
legend_titleargument can be used to override the default legend title. - The
axis_linesargument can be used to draw axis gridlines on the plot (both). - The
ls_lineargument can be set toTRUEto draw in a least squares line. - The
...is used for other labels on the plot, namely, the x- and y-axis labels.
- The
-
infer_*()- The
digitsargument can be specified with an integer value for the number of digits to round to. Defaults to 3. - The
captionargument can be used to override the default caption. - The
conf_lvlargument can be used to choose a different confidence level other than 0.95. (Not applicable toinfer_anova().)
- The
-
infer_1mean_test()andinfer_paired()- The
mu0argument can be used to specify the null hypothesis value, if different from 0.
- The
-
infer_1prop_test()- The
p0argument can be used to specify the null hypothesis value, if different from 0.5.
- The
-
inter_2prop_test()- This is an extra function should you be interested. It does not appear in the student cheatsheet.
Useful Features that are Part of Another Function / Package
- To take a random sample from a dataset, use
dplyr::slice_sample()with thenargument set to the number of rows you’d like to sample. - To make a pie chart (not recommended) you might want to use your own
plot code. Use
ggplot2::geom_bar()withcoord_polar()