f_boxplot | R Documentation |
Generates boxplots for all numeric variables in a given dataset, grouped by factor variables. The function automatically detects numeric and factor variables. It allows two output formats ('pdf', 'Word') and includes an option to add a general explanation about interpreting boxplots.
f_boxplot(
data = NULL,
formula = NULL,
fancy_names = NULL,
output_type = "pdf",
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE,
close_generated_files = FALSE,
open_generated_files = TRUE,
boxplot_explanation = TRUE,
detect_factors = TRUE,
jitter = FALSE,
width = 8,
height = 7,
units = "in",
res = 300,
las = 2
)
data |
A |
formula |
A formula specifying the factor to be plotted. More response variables can be added using |
fancy_names |
An optional named vector mapping column names in |
output_type |
Character string, specifying the output format: |
output_file |
A character string, specifying the name of the output file (without extension). If |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
close_generated_files |
Logical. If |
open_generated_files |
Logical. If |
boxplot_explanation |
A logical value indicating whether to include an explanation of how to interpret boxplots in the report. Defaults to |
detect_factors |
A logical value indicating whether to automatically detect factor variables in the dataset. Defaults to |
jitter |
A logical value, if |
width |
Numeric, png figure width default |
height |
Numeric, png figure height default |
units |
Character string, png figure units default |
res |
Numeric, png figure resolution default 300 dpi |
las |
An integer ( |
The function performs the following steps:
Detects numeric and factor variables in the dataset.
Generates boxplots for each numeric variable grouped by each factor variable.
Outputs the report in the specified format ('pdf', 'Word' or 'Rmd').
If output_type = "rmd"
is used it is adviced to use it in a chunk with {r, echo=FALSE, results='asis'}
If no factor variables are detected, the function stops with an error message since factors are required for creating boxplots.
This function will plot all numeric and factor candidates, use the function subset()
to prepare a selection of columns before submitting to f_boxplot()
.
Note that there is an optional jitter
option to plot all individual data points over the boxplots.
This function requires [Pandoc](https://github.com/jgm/pandoc/releases/tag) (version 1.12.3 or higher), a universal document converter.
Windows: Install Pandoc and ensure the installation folder
(e.g., "C:/Users/your_username/AppData/Local/Pandoc") is added to your system PATH.
macOS: If using Homebrew, Pandoc is typically installed in "/usr/local/bin". Alternatively, download the .pkg installer and verify that the binary’s location is in your PATH.
Linux: Install Pandoc through your distribution’s package manager (commonly installed in "/usr/bin" or "/usr/local/bin") or manually, and ensure the directory containing Pandoc is in your PATH.
If Pandoc is not found, this function may not work as intended.
Generates a report file ('pdf' or 'Word') with boxplots and, optionally, opens it with the default program. Returns NULL (no R object) when generating 'pdf' or 'Word' files. Can also return R Markdown code or 'PNG' files depending on the output format.
Sander H. van Delden plantmind@proton.me
# Example usage:
data(iris)
new_names = c(
"Sepal.Length" = "Sepal length (cm)" ,
"Sepal.Width" = "Sepal width (cm)",
"Petal.Length" = "Petal length (cm)",
"Petal.Width" = "Petal width (cm)",
"Species" = "Cultivar"
)
# Use the whole data.frame to generate a pdf report and don't open the pdf.
f_boxplot(iris, fancy_names = new_names, output_type = "pdf", open_generated_files = FALSE) #
# Use a formula to plot several response parameters (response 1 + response 2 etc)
# and generate a rmd output without boxplot_explanation.
data(mtcars)
f_boxplot(hp + disp ~ gear*cyl,
data=mtcars,
boxplot_explanation = FALSE,
output_type = "word",
open_generated_files = FALSE) # Do not automatically open the 'Word' file.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.