Skip to contents

This function generates dot plots for visualizing the results of longitudinal alpha diversity tests in microbiome data. It focuses on displaying how the alpha diversity indices change over time across different groups.

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 containing microbiome data and metadata.

test.list

A list of test results from `generate_alpha_per_time_test_long` or `generate_alpha_change_test_long` function, representing the statistical analysis of alpha diversity over time.

group.var

A string specifying the group variable in meta.dat for between-group comparisons in the dot plot.

time.var

A string representing the time variable in the meta.dat. This variable is used for the x-axis in the dot plot.

t0.level

The baseline time level for time series analysis.

ts.levels

The time series levels for analysis.

base.size

Optional; numeric, base font size for text elements in the plot. Default is 16.

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

Optional; a vector of colors for the gradient scale. If provided, it overrides the default color scale.

pdf

Optional; boolean, whether to save the plot as a PDF file.

pdf.wid

Optional; numeric, width of the saved PDF file.

pdf.hei

Optional; numeric, height of the saved PDF file.

Value

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

Details

The function uses ggplot2 to create dot plots, with options for customizing themes and aesthetics. It visualizes the significance and magnitude of changes in alpha diversity indices, indicated by color and size of the dots. The function allows for detailed customization of plot features, including base font size and theme choice.

The function prepares data by merging and transforming the results from `generate_alpha_per_time_test_long` to fit the plotting structure. It handles the display of statistical significance using color coding and sizes dots based on the estimate value from the statistical test.

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]
)
} # }