Skip to contents

Visualizes exposure variable distributions using boxplots or ridge plots, optionally grouped by a variable such as sex, smoking status, or exposure category.

Usage

plot_exposures(
  expomicset,
  exposure_cat = "all",
  exposure_cols = NULL,
  group_by = NULL,
  plot_type = "boxplot",
  alpha = 0.3,
  panel_sizes = rep(1, 100),
  title = "Exposure Levels by Category",
  xlab = "",
  ylab = "",
  facet_cols = NULL,
  group_cols = NULL,
  box_width = 0.1,
  fill_lab = ""
)

Arguments

expomicset

A MultiAssayExperiment object containing exposure data.

exposure_cat

A character string or vector specifying exposure category names (from codebook$category) to include. Use "all" to include all exposures.

exposure_cols

Optional character vector specifying exact exposure variables to plot.

group_by

A string specifying the column in colData(expomicset) used to fill the plot (e.g., "sex"). Defaults to NULL, in which case exposures are colored by category.

plot_type

Type of plot: "boxplot" (default) or "ridge".

alpha

Transparency level for background facet color strips. Default is 0.5.

panel_sizes

A numeric vector passed to ggh4x::force_panelsizes() for controlling facet widths or heights.

title

Plot title. Default is "Exposure Levels by Category".

xlab

X-axis label. Default is an empty string.

ylab

Y-axis label. Default is an empty string.

facet_cols

Optional vector of colors to use as background for facet categories. If NULL, a default palette is used.

group_cols

Optional named vector of colors for group_by levels. If NULL, a default palette is used.

fill_lab

Legend title for the fill aesthetic (e.g., "Sex" or "Exposure Group"). Default is "".

Value

A ggplot2 object showing exposure distributions, optionally grouped.

Details

This function:

  • Filters exposure data based on category or selected columns.

  • Merges variable metadata from metadata(expomicset)$codebook.

  • Supports either boxplot (vertical distributions per variable) or ridgeplot (horizontal density plots per variable).

  • If group_by is specified, that variable defines the plot fill color; otherwise, the fill is based on exposure category.

  • Facets by category using ggh4x::facet_grid2() with color-coded strip backgrounds.

Examples

if (FALSE) { # \dontrun{
plot_exposures(expomicset, exposure_cat = "Air Pollution")
plot_exposures(expomicset, group_by = "sex", plot_type = "ridge")
plot_exposures(expomicset, exposure_cols = c("hs_no2", "hs_pm25"), group_by = "smoking_status")
} # }