| Title: | Publication Ready Forest Plots for Estimand of Interest |
|---|---|
| Description: | Creates publication-quality forest plots and effect-size tables that display only the unadjusted and adjusted estimates for a user-specified exposure variable of interest, hiding confounder coefficients in accordance with causal inference principles. Supports logistic, linear, Poisson, and Cox proportional hazards models, with optional cumulative-adjustment visualisation. Built on 'ggplot2' and follows the tidyverse design philosophy. |
| Authors: | Chris Varghese [aut, cre] |
| Maintainer: | Chris Varghese <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-17 16:57:06 UTC |
| Source: | https://github.com/cran/ggadjustedforest |
A convenience wrapper around gg_adjusted_forest() that returns only the
formatted table. Useful when you want numeric summaries without producing a
graphic.
forest_table( data, outcome, exposure, covariates = NULL, model_type = "logistic", cumulative = FALSE, cumulative_labels = NULL, conf_level = 0.95, time_var = NULL, event_var = NULL, strata = NULL, cluster = NULL, weights = NULL, table_digits = 2 )forest_table( data, outcome, exposure, covariates = NULL, model_type = "logistic", cumulative = FALSE, cumulative_labels = NULL, conf_level = 0.95, time_var = NULL, event_var = NULL, strata = NULL, cluster = NULL, weights = NULL, table_digits = 2 )
data |
A data frame containing all variables. |
outcome |
Character string. Name of the outcome variable (ignored for
Cox models - use |
exposure |
Character string. Name of the exposure variable of interest. |
covariates |
Character vector of confounder/covariate names. In
non-cumulative mode all covariates are added together; in cumulative mode
they are added one at a time in the order supplied. Default |
model_type |
Character. One of |
cumulative |
Logical. If |
cumulative_labels |
Optional named character vector to rename the
cumulative model labels. Names should match the auto-generated labels
(e.g., |
conf_level |
Numeric. Confidence level for intervals. Default |
time_var |
Character. Name of the time variable (Cox model only). |
event_var |
Character. Name of the event indicator variable (Cox model only; should be 0/1 or logical). |
strata |
Character. Name of a stratification variable for Cox models.
Default |
cluster |
Character. Name of a clustering variable for cluster-robust
standard errors. Requires the sandwich and lmtest packages.
Default |
weights |
Character. Name of a survey/frequency weight variable.
Default |
table_digits |
Integer. Number of decimal places in the table. Default
|
A data frame with columns:
modelRow label (e.g., "Unadjusted", "Adjusted").
estimatePoint estimate (formatted character).
ciConfidence interval as a character string (e.g.,
"0.95–1.42").
formattedCombined estimate and CI (e.g.,
"1.15 (0.95–1.42)").
p.valueFormatted p-value character string.
nNumber of observations.
data(mtcars) mtcars$am <- as.integer(mtcars$am) forest_table( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), model_type = "logistic" )data(mtcars) mtcars$am <- as.integer(mtcars$am) forest_table( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), model_type = "logistic" )
Creates a publication-quality forest plot showing only the unadjusted and adjusted (or cumulatively adjusted) effect estimates for a specified exposure variable, hiding confounder coefficients in accordance with causal inference principles.
gg_adjusted_forest( data, outcome, exposure, covariates = NULL, model_type = "logistic", cumulative = FALSE, cumulative_labels = NULL, effect_label = NULL, title = NULL, ref_line = NULL, point_size = 4, point_shape = 15, line_size = 0.7, color = "black", colour = NULL, vline_color = "grey50", vline_linetype = "dashed", x_limits = NULL, x_breaks = NULL, log_scale = TRUE, conf_level = 0.95, time_var = NULL, event_var = NULL, strata = NULL, cluster = NULL, weights = NULL, show_table = TRUE, table_digits = 2 )gg_adjusted_forest( data, outcome, exposure, covariates = NULL, model_type = "logistic", cumulative = FALSE, cumulative_labels = NULL, effect_label = NULL, title = NULL, ref_line = NULL, point_size = 4, point_shape = 15, line_size = 0.7, color = "black", colour = NULL, vline_color = "grey50", vline_linetype = "dashed", x_limits = NULL, x_breaks = NULL, log_scale = TRUE, conf_level = 0.95, time_var = NULL, event_var = NULL, strata = NULL, cluster = NULL, weights = NULL, show_table = TRUE, table_digits = 2 )
data |
A data frame containing all variables. |
outcome |
Character string. Name of the outcome variable (ignored for
Cox models - use |
exposure |
Character string. Name of the exposure variable of interest. |
covariates |
Character vector of confounder/covariate names. In
non-cumulative mode all covariates are added together; in cumulative mode
they are added one at a time in the order supplied. Default |
model_type |
Character. One of |
cumulative |
Logical. If |
cumulative_labels |
Optional named character vector to rename the
cumulative model labels. Names should match the auto-generated labels
(e.g., |
effect_label |
Character. X-axis label. Defaults to |
title |
Character. Plot title. Default |
ref_line |
Numeric. Position of the vertical reference line. Defaults
to |
point_size |
Numeric. Size of the point estimate symbol. Default |
point_shape |
Integer. ggplot2 shape code. Default |
line_size |
Numeric. Thickness of the CI lines. Default |
color |
Character. Colour for points and CI lines. Default |
colour |
Alias for |
vline_color |
Character. Colour of the reference line. Default
|
vline_linetype |
Character. Linetype of the reference line. Default
|
x_limits |
Numeric vector of length 2. Manual x-axis limits. Default
|
x_breaks |
Numeric vector. Manual x-axis break positions. Default
|
log_scale |
Logical. Use log scale on the x-axis for ratio models.
Default |
conf_level |
Numeric. Confidence level for intervals. Default |
time_var |
Character. Name of the time variable (Cox model only). |
event_var |
Character. Name of the event indicator variable (Cox model only; should be 0/1 or logical). |
strata |
Character. Name of a stratification variable for Cox models.
Default |
cluster |
Character. Name of a clustering variable for cluster-robust
standard errors. Requires the sandwich and lmtest packages.
Default |
weights |
Character. Name of a survey/frequency weight variable.
Default |
show_table |
Logical. Combine the forest plot with a formatted table
panel (using patchwork). Default |
table_digits |
Integer. Number of decimal places in the table. Default
|
An object of class ggadjustedforest (a list) with components:
plotThe combined ggplot2/patchwork plot object.
When show_table = FALSE this is just the forest plot.
tableA data frame with columns model, estimate,
conf.low, conf.high, p.value, and n.
formatted_tableA data frame with a formatted column
containing strings like "1.23 (1.01-1.55)".
# Logistic regression example data(mtcars) mtcars$am <- as.integer(mtcars$am) # binary outcome result <- gg_adjusted_forest( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), model_type = "logistic", title = "Effect of Horsepower on Transmission Type" ) result$table # Cumulative adjustment result2 <- gg_adjusted_forest( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), cumulative = TRUE ) result2$table# Logistic regression example data(mtcars) mtcars$am <- as.integer(mtcars$am) # binary outcome result <- gg_adjusted_forest( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), model_type = "logistic", title = "Effect of Horsepower on Transmission Type" ) result$table # Cumulative adjustment result2 <- gg_adjusted_forest( data = mtcars, outcome = "am", exposure = "hp", covariates = c("wt", "cyl"), cumulative = TRUE ) result2$table
Plot method for ggadjustedforest objects
## S3 method for class 'ggadjustedforest' plot(x, ...)## S3 method for class 'ggadjustedforest' plot(x, ...)
x |
An object of class |
... |
Additional arguments (currently ignored). |
Invisibly returns the plot object.
Print method for ggadjustedforest objects
## S3 method for class 'ggadjustedforest' print(x, ...)## S3 method for class 'ggadjustedforest' print(x, ...)
x |
An object of class |
... |
Additional arguments (currently ignored). |
Invisibly returns x.