| Title: | Publication Ready Forest Plots for Estimand of Interest |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Language: | en-GB |
| RoxygenNote: | 8.0.0 |
| Depends: | R (≥ 4.1.0) |
| Imports: | ggplot2 (≥ 3.4.0), dplyr (≥ 1.1.0), rlang (≥ 1.1.0), broom (≥ 1.0.0), survival (≥ 3.5.0), patchwork (≥ 1.2.0), scales (≥ 1.3.0), tibble (≥ 3.2.0) |
| Suggests: | sandwich, lmtest, testthat (≥ 3.0.0), knitr, rmarkdown, finalfit |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| URL: | https://github.com/kriz98/gg_adjusted_forest |
| BugReports: | https://github.com/kriz98/gg_adjusted_forest/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-07-08 13:50:14 UTC; cvar706 |
| Author: | Chris Varghese [aut, cre] |
| Maintainer: | Chris Varghese <chris.varghese@auckland.ac.nz> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-17 12:40:02 UTC |
Extract a formatted effect-size table without generating a plot
Description
A convenience wrapper around gg_adjusted_forest() that returns only the
formatted table. Useful when you want numeric summaries without producing a
graphic.
Usage
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
)
Arguments
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
|
Value
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.
Examples
data(mtcars)
mtcars$am <- as.integer(mtcars$am)
forest_table(
data = mtcars,
outcome = "am",
exposure = "hp",
covariates = c("wt", "cyl"),
model_type = "logistic"
)
Forest plot of unadjusted and adjusted effects for a single exposure
Description
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.
Usage
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
)
Arguments
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
|
Value
An object of class ggadjustedforest (a list) with components:
plotThe combined ggplot2/patchwork plot object. When
show_table = FALSEthis is just the forest plot.tableA data frame with columns
model,estimate,conf.low,conf.high,p.value, andn.formatted_tableA data frame with a
formattedcolumn containing strings like"1.23 (1.01-1.55)".
Examples
# 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
Description
Plot method for ggadjustedforest objects
Usage
## S3 method for class 'ggadjustedforest'
plot(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments (currently ignored). |
Value
Invisibly returns the plot object.
Print method for ggadjustedforest objects
Description
Print method for ggadjustedforest objects
Usage
## S3 method for class 'ggadjustedforest'
print(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments (currently ignored). |
Value
Invisibly returns x.