plot.TransHDM: Visualize TransHDM Mediation Analysis Results

View source: R/plot_TransHDM.R

plot.TransHDMR Documentation

Visualize TransHDM Mediation Analysis Results

Description

S3 plot method for objects of class "TransHDM". Produces a bar chart of the overall effects (indirect, direct, total, proportion mediated), individual mediator effects, or p-values.

Usage

## S3 method for class 'TransHDM'
plot(
  x,
  type = c("overall", "mediator", "pvalue", "alpha_beta"),
  fill = "white",
  color = "black",
  linewidth = 0.5,
  size.text = 3,
  show.values = TRUE,
  digits = 3,
  base_size = 12,
  label = c("significant", "all", "none"),
  ...
)

Arguments

x

An object of class "TransHDM", returned by TransHDM().

type

Character string specifying the type of plot: "overall" (default) for overall effect estimates, "mediator" for individual mediator contributions (\hat\alpha \times \hat\beta), "pvalue" for joint p-values (-\log_{10}(\text{ab\_pv})), or "alpha_beta" for a scatter plot of exposure–mediator versus mediator–outcome effects, coloured by significance.

fill

Bar fill color. Default is "white".

color

Bar border color. Default is "black".

linewidth

Bar border line width. Default is 0.5.

size.text

Numeric; size of value labels on bars. Default is 3.5.

show.values

Logical; if TRUE (default), numeric values are displayed on each bar.

digits

Integer; number of decimal places for displayed values. Default is 3.

base_size

Numeric; base font size passed to theme_classic. Default is 12.

label

For type = "alpha_beta" only: "significant" (default) labels only significant mediators, "all" labels every mediator, "none" suppresses labels. Requires the ggrepel package.

...

Additional arguments (currently unused).

Value

A ggplot object. The plot is printed automatically when called interactively.

Examples


set.seed(123)
target_data <- gen_simData_homo(n = 50, p_x = 3, p_m = 20, rho = 0.1)$data
source_data <- gen_simData_homo(n = 100, p_x = 3, p_m = 20, rho = 0.1,
  source = TRUE, transferable = TRUE)$data
result <- TransHDM(
  target_data = target_data, source_data = source_data,
  Y = "Y", D = "D", M = paste0("M", 1:20), X = paste0("X", 1:3),
  transfer = TRUE, ncore = 1, topN = 10
)
plot(result)
plot(result, type = "mediator")
plot(result, type = "pvalue")
plot(result, type = "alpha_beta")



TransHDM documentation built on Nov. 24, 2026, 9:06 a.m.