Creates comprehensive visualizations comparing data distributions and patterns before and after preprocessing steps. Generates density plots and box plots from either sample or feature perspectives to assess preprocessing effectiveness. Supports both PCA and PLS scaled data visualization with intelligent random sampling for large datasets.

plot_BeforeAfter(
  data,
  scaled = "PLS",
  group_by = "Sample",
  n_random_samples = 30L,
  n_random_features = 30L,
  seed = 123L
)

Arguments

data

List. A preprocessing results object from perform_PreprocessingPeakData function containing original data, transformed data, and metadata.

scaled

Character. Specifies which preprocessed data to visualize:

  • "PCA": Uses PCA-scaled preprocessed data

  • "PLS": Uses PLS-scaled preprocessed data

Default: "PLS"

group_by

Character. Visualization perspective:

  • "Sample": Visualizes sample-wise distributions

  • "Feature": Visualizes feature-wise distributions

Default: "Sample"

n_random_samples

Integer. Number of random samples to display in box plots. If NULL, uses all samples. If specified number exceeds total samples, uses all available samples. Default: 30

n_random_features

Integer. Number of random features to display in box plots. If NULL, uses all features. If specified number exceeds total features, uses all available features. Default: 30

seed

Integer. Random seed for reproducible sample/feature selection. Default: 123

Value

List containing:

  • FunctionOrigin: Character indicating function source

  • data_before: Matrix of original data (non-QC samples)

  • data_after: Matrix of transformed data (non-QC samples)

  • plot_density_before: ggplot2 density plot of original data

  • plot_density_after: ggplot2 density plot of transformed data

  • plot_box_before: ggplot2 box plot of original data

  • plot_box_after: ggplot2 box plot of transformed data

  • plot_combined: Combined 2x2 grid plot

  • processing_info: List with processing metadata

Author

John Lennon L. Calorio

Examples

if (FALSE) { # \dontrun{
# Basic usage with PLS scaling
plots <- plot_BeforeAfter(
  data = preprocessing_results,
  scaled = "PLS",
  group_by = "Sample"
)

# Feature perspective with PCA scaling
feature_plots <- plot_BeforeAfter(
  data = preprocessing_results,
  scaled = "PCA",
  group_by = "Feature",
  n_random_features = 20
)

# Display combined plot
print(plots$plot_combined)
} # }