Generates a forest plot using ggplot2 from a data frame containing estimates, confidence intervals, and sample sizes. This function is designed to be a component of a combined table/plot output (e.g., used by g_forest()).

gg_forest_plot(data, header = "", xlim = c(0.1, 10), logx = TRUE, vline = 1)

Arguments

data

(data.frame)
A data frame (tibble) containing the plot data. It must include columns: estimate, ci_lower, ci_upper, and n (for point size).

header

Forest header

xlim

(numeric(2))
A numeric vector of length 2 specifying the limits of the x-axis (e.g., c(0.1, 10)).

logx

(logical(1))
A logical value indicating whether the x-axis should be log-transformed (i.e., using ggplot2::scale_x_log10()). The default is TRUE, which is typical for effect measures like Odds Ratios or Hazard Ratios.

vline

(numeric(1))
A numeric value specifying the x-intercept for the vertical reference line (line of no effect). The default is 1.

Value

A 'ggplot' object representing the forest plot.

Examples

if (FALSE) { # \dontrun{
# Assuming 'forest_data' is structured correctly:
forest_data <- data.frame(
  estimate = c(0.5, 2.0),
  ci_lower = c(0.2, 1.5),
  ci_upper = c(0.9, 3.5),
  n = c(100, 250)
)

gg_forest_plot(forest_data)
gg_forest_plot(forest_data, xlim = c(0.05, 50), vline = 1)
} # }