% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mr_forest.R
\name{MR_forest}
\alias{MR_forest}
\title{Generate Forest Plots across Multiple MR Methods}
\usage{
MR_forest(
  summary_df,
  effect,
  custom_xlim = NULL,
  dot_size = 3,
  axis_text_size = 10,
  axis_title_size = 12,
  pval_text_size = 3,
  clamp_nonpositive = FALSE,
  log_scale = TRUE
)
}
\arguments{
\item{summary_df}{MR results data frame, typically the output from run_mr_analysis().}

\item{effect}{Character string or vector indicating the effect scale
("Beta", "OR", or "HR").}

\item{custom_xlim}{Optional numeric vector of length 2 for x-axis limits.}

\item{dot_size}{Numeric value specifying the point size. Default is 3.}

\item{axis_text_size}{Numeric value for axis font size.}

\item{axis_title_size}{Numeric value for title font size.}

\item{pval_text_size}{Numeric value for p-value label size.}

\item{clamp_nonpositive}{Logical; whether non-positive estimates should
be clamped to a small positive value before log-transformation.}

\item{log_scale}{Logical; if \code{TRUE} and \code{effect} is \code{"OR"}
or \code{"HR"}, the x-axis label shows \code{log(OR)} or \code{log(HR)}.
Note that \code{MR_forest} always plots on the log scale internally for
OR/HR; this argument only controls the axis label. Default is \code{TRUE}.}
}
\value{
An \code{MRForestPlots} object containing one \code{ggplot}
  per outcome-exposure pair, with causal estimates compared across MR
  methods. Use \code{export_forest_plots()} to write plots to disk
  with optional filtering.
}
\description{
Creates a forest plot comparing causal estimates across different MR
methods (e.g., IVW, RAPS, Egger).
}
\examples{
\donttest{
data("merged_data")
input3   <- harmonize_mr_data(df = merged_data)$input_df
outcome3 <- run_mr_analysis(
  MR_input_data     = input3,
  outcome.form      = c("Beta","OR"),
  use_ivw           = TRUE,
  use_raps          = TRUE,
  use_median        = TRUE,
  use_egger         = TRUE,
  use_mr_presso     = TRUE,
  use_mr_horse      = TRUE,
  use_mr_grip       = TRUE,
  NbDistribution    = 1000,
  SignifThreshold   = 0.05,
  mr_horse_n_iter   = 5000,
  mr_horse_n_burnin = 1000,
  mr_grip_parameters = NULL
)

mr_plots <- MR_forest(
  summary_df        = outcome3,
  effect            = c("Beta","OR"),
  custom_xlim       = NULL,
  dot_size          = 3,
  axis_text_size    = 10,
  axis_title_size   = 12,
  pval_text_size    = 3,
  clamp_nonpositive = FALSE,
  log_scale         = TRUE
)

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

# Export all method-level plots as PDF (commented — writes to disk)
export_forest_plots(mr_plots, save_dir = tempdir(), file_type = "png")

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

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

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