GWAS_forest: Generate Instrument-level Forest Plots for Mendelian...

View source: R/mr_forest.R

GWAS_forestR Documentation

Generate Instrument-level Forest Plots for Mendelian Randomization

Description

Creates a forest plot for each instrument (SNP) within the MR analysis, including a pooled IVW estimate at the top for comparison.

Usage

GWAS_forest(
  MR_input_data,
  report_form = "Beta",
  custom_xlim = NULL,
  dot_size = 2,
  axis_text_size = 10,
  axis_title_size = 12,
  digits = 2,
  label_text_size = 3,
  log_scale = FALSE
)

Arguments

MR_input_data

Harmonised MR input data frame. Must contain Outcome, Exposure, Instrument, beta_exposure, se_exposure, beta_outcome, and se_outcome columns.

report_form

Character string or vector indicating the standard output scale for each outcome (e.g., "Beta", "OR", "HR"). Defaults to "Beta".

custom_xlim

Optional numeric vector of length 2 providing custom limits for the x-axis. If NULL, limits are determined by the data.

dot_size

Numeric value specifying the size of the points. Default is 2.

axis_text_size

Numeric value specifying the font size for axis labels. Default is 10.

axis_title_size

Numeric value specifying the font size for axis titles. Default is 12.

digits

Integer specifying the number of decimal places for labels. Default is 2.

label_text_size

Numeric value specifying the size of estimate labels (Beta/OR/HR and 95 percent CI) shown on the plot. Default is 3.

log_scale

Logical; if TRUE and report_form is "OR" or "HR", estimates are kept on the log scale instead of being exponentiated. The x-axis label becomes log(OR) or log(HR) and the reference line is drawn at 0. Default is FALSE.

Value

A GWASForestPlots object containing one ggplot per outcome-exposure pair, with instrument-level (SNP) causal estimates and a pooled IVW estimate. Use export_forest_plots() to write plots to disk with optional filtering.

Examples


data("merged_data")
input3 <- harmonize_mr_data(df = merged_data)$input_df

gwas_plots <- GWAS_forest(
  MR_input_data   = input3,
  report_form     = c("Beta","OR"),
  custom_xlim     = NULL,
  dot_size        = 2,
  axis_text_size  = 10,
  axis_title_size = 12,
  digits          = 2,
  label_text_size = 3,
  log_scale       = FALSE
)

# Retrieve the exact outcome/exposure labels stored in the object
out_name <- gwas_plots@outcomes[1]   # "fi_49item"
exp_name <- gwas_plots@exposures[1]  # "Zn"

# Export all instrument-level plots as PNG (commented — writes to disk)
# export_forest_plots(gwas_plots, save_dir = tempdir(), file_type = "jpeg")

# Export plots for one outcome only
# export_forest_plots(gwas_plots, save_dir = tempdir(), outcome = out_name)

# Export plots for one exposure only
# export_forest_plots(gwas_plots, save_dir = tempdir(), exposure = exp_name)

# Export one specific outcome-exposure pair
# export_forest_plots(gwas_plots, save_dir = tempdir(), outcome = out_name, exposure = exp_name)


autoMR documentation built on June 12, 2026, 9:07 a.m.

Related to GWAS_forest in autoMR...