Generate Boxplot of Individual Taxa Abundance Over Time
Source:R/generate_taxa_indiv_boxplot_long.R
generate_taxa_indiv_boxplot_long.Rd
This function creates a boxplot showing the abundance distribution of individual taxa at a specified taxonomic level over time from longitudinal data. It takes a MicrobiomeStat data object as input.
Usage
generate_taxa_indiv_boxplot_long(
data.obj,
subject.var,
time.var,
t0.level = NULL,
ts.levels = NULL,
group.var = NULL,
strata.var = NULL,
feature.level = NULL,
features.plot = NULL,
feature.dat.type = c("count", "proportion", "other"),
top.k.plot = NULL,
top.k.func = NULL,
transform = c("sqrt", "identity", "log"),
prev.filter = 0.01,
abund.filter = 0.01,
base.size = 16,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 11,
pdf.hei = 8.5,
...
)
Arguments
- data.obj
A list object in a format specific to MicrobiomeStat, which can include components such as feature.tab (matrix), feature.ann (matrix), meta.dat (data.frame), tree, and feature.agg.list (list).
- subject.var
A character string specifying the subject variable in the metadata.
- time.var
A character string specifying the time variable in the metadata.
- t0.level
Character or numeric, baseline time point for longitudinal analysis, e.g. "week_0" or 0. Required.
- ts.levels
Character vector, names of follow-up time points, e.g. c("week_4", "week_8"). Required.
- group.var
Optional grouping variable in metadata.
- strata.var
Optional stratification variable in metadata.
- feature.level
Taxonomic level(s) for boxplots.
- features.plot
A character vector specifying which feature IDs (e.g. OTU IDs) to plot. Default is NULL, in which case features will be selected based on `top.k.plot` and `top.k.func`.
- feature.dat.type
The type of the feature data, which determines how the data is handled in downstream analyses. Should be one of: - "count": Raw count data, will be normalized by the function. - "proportion": Data that has already been normalized to proportions/percentages. - "other": Custom abundance data that has unknown scaling. No normalization applied. The choice affects preprocessing steps as well as plot axis labels. Default is "count", which assumes raw OTU table input.
- top.k.plot
A numeric value specifying the number of top taxa to be plotted if features.plot is NULL. If NULL (default), all taxa will be plotted.
- top.k.func
A function to compute the top k taxa if features.plot is NULL. If NULL (default), the mean function will be used.
- transform
A string indicating the transformation to apply to the data before plotting. Options are: - "identity": No transformation (default) - "sqrt": Square root transformation - "log": Logarithmic transformation. Zeros are replaced with half of the minimum non-zero value for each taxon before log transformation.
- prev.filter
Numeric value specifying the minimum prevalence threshold for filtering taxa before analysis. Taxa with prevalence below this value will be removed. Prevalence is calculated as the proportion of samples where the taxon is present. Default 0 removes no taxa by prevalence filtering.
- abund.filter
Numeric value specifying the minimum abundance threshold for filtering taxa before analysis. Taxa with mean abundance below this value will be removed. Abundance refers to counts or proportions depending on
feature.dat.type
. Default 0 removes no taxa by abundance filtering.- base.size
Base font size for the generated plots.
- theme.choice
Plot theme choice. Specifies the visual style of the plot. Can be one of the following pre-defined themes: - "prism": Utilizes the ggprism::theme_prism() function from the ggprism package, offering a polished and visually appealing style. - "classic": Applies theme_classic() from ggplot2, providing a clean and traditional look with minimal styling. - "gray": Uses theme_gray() from ggplot2, which offers a simple and modern look with a light gray background. - "bw": Employs theme_bw() from ggplot2, creating a classic black and white plot, ideal for formal publications and situations where color is best minimized. - "light": Implements theme_light() from ggplot2, featuring a light theme with subtle grey lines and axes, suitable for a fresh, modern look. - "dark": Uses theme_dark() from ggplot2, offering a dark background, ideal for presentations or situations where a high-contrast theme is desired. - "minimal": Applies theme_minimal() from ggplot2, providing a minimalist theme with the least amount of background annotations and colors. - "void": Employs theme_void() from ggplot2, creating a blank canvas with no axes, gridlines, or background, ideal for custom, creative plots. Each theme option adjusts various elements like background color, grid lines, and font styles to match the specified aesthetic. Default is "bw", offering a universally compatible black and white theme suitable for a wide range of applications.
- custom.theme
A custom ggplot theme provided as a ggplot2 theme object. This allows users to override the default theme and provide their own theme for plotting. Custom themes are useful for creating publication-ready figures with specific formatting requirements.
To use a custom theme, create a theme object with ggplot2::theme(), including any desired customizations. Common customizations for publication-ready figures might include adjusting text size for readability, altering line sizes for clarity, and repositioning or formatting the legend. For example:
“`r my_theme <- ggplot2::theme( axis.title = ggplot2::element_text(size=14, face="bold"), # Bold axis titles with larger font axis.text = ggplot2::element_text(size=12), # Slightly larger axis text legend.position = "top", # Move legend to the top legend.background = ggplot2::element_rect(fill="lightgray"), # Light gray background for legend panel.background = ggplot2::element_rect(fill="white", colour="black"), # White panel background with black border panel.grid.major = ggplot2::element_line(colour = "grey90"), # Lighter color for major grid lines panel.grid.minor = ggplot2::element_blank(), # Remove minor grid lines plot.title = ggplot2::element_text(size=16, hjust=0.5) # Centered plot title with larger font ) “`
Then pass `my_theme` to `custom.theme`. If `custom.theme` is NULL (the default), the theme is determined by `theme.choice`. This flexibility allows for both easy theme selection for general use and detailed customization for specific presentation or publication needs.
- palette
An optional parameter specifying the color palette to be used for the plot. It can be either a character string specifying the name of a predefined palette or a vector of color codes in a format accepted by ggplot2 (e.g., hexadecimal color codes). Available predefined palettes include 'npg', 'aaas', 'nejm', 'lancet', 'jama', 'jco', and 'ucscgb', inspired by various scientific publications and the `ggsci` package. If `palette` is not provided or an unrecognized palette name is given, a default color palette will be used. Ensure the number of colors in the palette is at least as large as the number of groups being plotted.
Logical, if TRUE save plot as a multi-page PDF file. Default is TRUE.
- file.ann
Optional string for file annotation to add to PDF name.
- pdf.wid
Width of the PDF plots.
- pdf.hei
Height of the PDF plots.
- ...
Additional arguments passed to ggplot2 functions.
Examples
if (FALSE) { # \dontrun{
# Generate the boxplot pair
data(ecam.obj)
generate_taxa_indiv_boxplot_long(
data.obj = ecam.obj,
subject.var = "studyid",
time.var = "month_num",
t0.level = NULL,
ts.levels = NULL,
group.var = "diet",
strata.var = NULL,
feature.level = c("Phylum"),
feature.dat.type = "proportion",
transform = "log",
prev.filter = 0.01,
abund.filter = 0.01,
base.size = 20,
theme.choice = "bw",
custom.theme = NULL,
palette = c("#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf", "#aec7e8",
"#ffbb78", "#98df8a", "#ff9896", "#c5b0d5", "#c49c94", "#f7b6d2",
"#c7c7c7", "#dbdb8d", "#9edae5", "#f0f0f0", "#3182bd"),
pdf = TRUE,
file.ann = NULL,
pdf.wid = 25,
pdf.hei = 8.5
)
data(peerj32.obj)
generate_taxa_indiv_boxplot_long(
data.obj = peerj32.obj,
subject.var = "subject",
time.var = "time",
t0.level = "1",
ts.levels = "2",
group.var = "group",
strata.var = NULL,
feature.level = c("Family"),
features.plot = NULL,
feature.dat.type = "other",
top.k.plot = NULL,
top.k.func = NULL,
transform = "log",
prev.filter = 0.01,
abund.filter = 0.01,
base.size = 20,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 11,
pdf.hei = 8.5
)
} # }