combat_plot_gen function

Generate Diagnostic Plots for Batch Effect Analysis

Generate Diagnostic Plots for Batch Effect Analysis

This function generates a variety of diagnostic plots for analyzing batch effects and their relationships with features and covariates. Depending on the specified plot type, it can create density plots, box plots, residual plots, PCA plots, T-SNE plots, and empirical Bayes diagnostic plots.

combat_plot_gen( result, f = NULL, batch_control = "No", batch_level = NULL, plot_name, c = NULL, smooth_method = "lm", alpha = 0.2, char_plot_type = "boxplot", text_status = "No", color = "No", label = "No", angle = 0, PC1 = NULL, PC2 = NULL, eb = TRUE, eb_df = NULL )

Arguments

  • result: A list derived from visual_prep() that contains datasets and statistical test results for Shiny visualization.
  • f: A string specifying the feature of interest for visualization.
  • batch_control: A string indicating whether to include batch-specific controls. Defaults to "No".
  • batch_level: A vector specifying the batch levels to include in the plot. Used only when batch_control is not "No".
  • plot_name: A string specifying the type of plot to generate. Options include "batch_density", "cov_feature", "batch_summary", "cov_distribution", "resid_add", "resid_mul", "pca", "tsne", "eb_location", and "eb_scale".
  • c: A string specifying the covariate of interest for "cov_feature" or "cov_distribution" plots.
  • smooth_method: A string specifying the smoothing method for trend lines. Defaults to "lm" (linear model).
  • alpha: A numeric value between 0 and 1 controlling the transparency of trend lines. Defaults to 0.2.
  • char_plot_type: A string specifying the type of plot for categorical covariates. Options include "boxplot", "boxplot with points", and "density plot". Defaults to "boxplot".
  • text_status: A string indicating whether to display text annotations in the plot. Defaults to "No".
  • color: A string indicating whether to use color coding in plots. Defaults to "No".
  • label: A string indicating whether to include axis labels in the plot. Defaults to "No".
  • angle: A numeric value specifying the angle of x-axis labels. Defaults to 0.
  • PC1: A string specifying the first principal component for PCA plots.
  • PC2: A string specifying the second principal component for PCA plots.
  • eb: A logical value indicating whether to include empirical Bayes prior information in the plot. Defaults to TRUE.
  • eb_df: A data frame containing empirical Bayes information for generating eb_location and eb_scale plots.

Returns

A ggplot object representing the specified diagnostic plot.

Details

The function dynamically generates plots based on the plot_name parameter:

  • "batch_density": Density plots of features by batch levels.
  • "cov_feature": Covariate vs. feature plots with optional batch adjustments.
  • "batch_summary": Bar plots summarizing batch-level distributions.
  • "cov_distribution": Covariate distributions stratified by batch.
  • "resid_add": Additive residual box plots.
  • "resid_mul": Multiplicative residual box plots.
  • "pca": Principal Component Analysis (PCA) plots.
  • "tsne": T-SNE plots for dimensionality reduction.
  • "eb_location": Empirical Bayes location parameter density plots.
  • "eb_scale": Empirical Bayes scale parameter density plots.

Examples

if(interactive()){ result <- visual_prep(type = "lm", features = "thickness.left.cuneus", batch = "manufac", covariates = "AGE", df = adni[1:100, ], mdmr = FALSE, cores = 1) combat_plot_gen(result, f = "thickness.left.cuneus", plot_name = "batch_density") combat_plot_gen(result, f = "thickness.left.cuneus", c = "AGE", plot_name = "cov_feature") }