| MR_forest | R Documentation |
Creates a forest plot comparing causal estimates across different MR methods (e.g., IVW, RAPS, Egger).
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
)
summary_df |
MR results data frame, typically the output from run_mr_analysis(). |
effect |
Character string or vector indicating the effect scale ("Beta", "OR", or "HR"). |
custom_xlim |
Optional numeric vector of length 2 for x-axis limits. |
dot_size |
Numeric value specifying the point size. Default is 3. |
axis_text_size |
Numeric value for axis font size. |
axis_title_size |
Numeric value for title font size. |
pval_text_size |
Numeric value for p-value label size. |
clamp_nonpositive |
Logical; whether non-positive estimates should be clamped to a small positive value before log-transformation. |
log_scale |
Logical; if |
An MRForestPlots object containing one ggplot
per outcome-exposure pair, with causal estimates compared across MR
methods. Use export_forest_plots() to write plots to disk
with optional filtering.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.