Skip to contents

Generates dot plots visualizing the results of longitudinal alpha diversity tests, showing effect sizes and p-values across time points.

Usage

generate_alpha_per_time_dotplot_long(
  data.obj,
  test.list,
  group.var,
  time.var,
  t0.level,
  ts.levels,
  base.size = 16,
  theme.choice = "bw",
  custom.theme = NULL,
  palette = rev(c("white", "#92c5de", "#0571b0", "#f4a582", "#ca0020")),
  pdf = FALSE,
  pdf.wid = 7,
  pdf.hei = 5
)

Arguments

data.obj

A MicrobiomeStat data object, which is a list containing at minimum the following components:

  • feature.tab: A matrix of feature abundances (taxa/genes as rows, samples as columns)

  • meta.dat: A data frame of sample metadata (samples as rows)

Optional components include:

  • feature.ann: A matrix/data frame of feature annotations (e.g., taxonomy)

  • tree: A phylogenetic tree object (class "phylo")

  • feature.agg.list: Pre-aggregated feature tables by taxonomy

Data objects can be created using converters like mStat_convert_phyloseq_to_data_obj or importers like mStat_import_qiime2_as_data_obj.

test.list

A list of test results from `generate_alpha_per_time_test_long` or `generate_alpha_change_test_long` function.

group.var

Character string specifying the column name in meta.dat containing the grouping variable (e.g., treatment, condition, phenotype). Used for between-group comparisons.

time.var

Character string specifying the column name in meta.dat containing the time variable. Required for longitudinal and paired analyses. Supports character/factor labels (e.g., "baseline", "week4") and numeric values. Some trend/volatility methods require numeric or coercible-to-numeric time values.

t0.level

Character or numeric value specifying the baseline time point for longitudinal or paired analyses. Should match a value in the time.var column.

ts.levels

Character vector specifying the follow-up time points for longitudinal or paired analyses. Should match values in the time.var column.

base.size

Numeric value specifying the base font size for plot text elements. Default is typically 16.

theme.choice

Character string specifying the ggplot2 theme to use. Options include:

  • "bw": Black and white theme (theme_bw)

  • "classic": Classic theme (theme_classic)

  • "gray": Gray theme (theme_gray)

  • "light": Light theme (theme_light)

  • "dark": Dark theme (theme_dark)

  • "minimal": Minimal theme (theme_minimal)

  • "void": Void theme (theme_void)

  • "prism": GraphPad Prism-like theme

Can also use a custom ggplot2 theme object via custom.theme.

custom.theme

A custom ggplot2 theme object to override theme.choice. Should be created using ggplot2::theme() or a complete theme function.

palette

Character vector of colors or a named palette for the plot. If NULL, uses default MicrobiomeStat color scheme. Can be:

  • A vector of color codes (e.g., c("#E41A1C", "#377EB8"))

  • A palette name recognized by the plotting function

pdf

Logical. If TRUE, saves the plot(s) to PDF file(s) in the current working directory. Default is TRUE.

pdf.wid

Numeric value specifying the width of PDF output in inches. Default is typically 11.

pdf.hei

Numeric value specifying the height of PDF output in inches. Default is typically 8.5.

Value

A list of ggplot objects, each representing a dot plot for a specific group. The plots can be further customized or directly rendered.

Examples

if (FALSE) { # \dontrun{
# Example 1: Analyzing the ECAM dataset
data("ecam.obj")
# Analyzing the impact of delivery method on microbial composition over months
result1 <- generate_alpha_per_time_test_long(
  data.obj = ecam.obj,
  alpha.name = c("shannon", "simpson", "observed_species", "pielou"),
  time.var = "month_num",
  t0.level = unique(ecam.obj$meta.dat$month_num)[1],
  ts.levels = unique(ecam.obj$meta.dat$month_num)[-1],
  group.var = "delivery",
  adj.vars = "diet"
)
# Visualizing the results for the ECAM dataset
dotplot_ecam <- generate_alpha_per_time_dotplot_long(
  data.obj = ecam.obj,
  test.list = result1,
  group.var = "delivery",
  time.var = "month_num",
  t0.level = unique(ecam.obj$meta.dat$month_num)[1],
  ts.levels = unique(ecam.obj$meta.dat$month_num)[-1]
)

# Example 2: Analyzing the Type 2 Diabetes dataset
data("subset_T2D.obj")
# Longitudinal analysis of microbial changes in different racial groups
result2 <- generate_alpha_per_time_test_long(
  data.obj = subset_T2D.obj,
  alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou"),
  time.var = "visit_number",
  t0.level = unique(subset_T2D.obj$meta.dat$visit_number)[1],
  ts.levels = unique(subset_T2D.obj$meta.dat$visit_number)[-1],
  group.var = "subject_race",
  adj.vars = "sample_body_site"
)
# Visualizing the results for the Type 2 Diabetes dataset
dotplot_T2D <- generate_alpha_per_time_dotplot_long(
  data.obj = subset_T2D.obj,
  test.list = result2,
  group.var = "subject_race",
  time.var = "visit_number",
  t0.level = unique(subset_T2D.obj$meta.dat$visit_number)[1],
  ts.levels = unique(subset_T2D.obj$meta.dat$visit_number)[-1]
)
} # }