Publication-Ready Forest Plots with 'ggplot2'

Transform model coefficients into flexible forest plots using 'ggplot2'. Provides helpers to standardize coefficient data from a range of modelling workflows and render publication-ready forest plots with a consistent interface.


ggforestplotR


R-CMD-check Codecov CRAN version

Overview

ggforestplotR provides a ggplot2-first workflow for building forest plots from tidy coefficient tables or fitted model objects.

Installation

CRAN

install.packages("ggforestplotR")

Development

#install.packages("remotes")
remotes::install_github("thatoneguy006/ggforestplotR")

Supported workflows

ggforestplotR currently supports two core workflows:

  • Plot directly from a table of coefficient data.
  • Plot using data from a fitted model object.

Both workflows are converted to a validated forest_data object before plotting. This object records the effect scale, confidence level, reference value, and source provenance independently of the fitted-model class.

Basic example

library(ggforestplotR)
library(ggplot2)

sectioned_coefs <- data.frame(
  term = c("Age", "BMI", "Smoking", "Stage II", "Stage III", "Nodes"),
  estimate = c(0.10, -0.08, 0.20, 0.34, 0.52, 0.28),
  conf.low = c(0.02, -0.16, 0.05, 0.12, 0.20, 0.06),
  conf.high = c(0.18, 0.00, 0.35, 0.56, 0.84, 0.50),
  section = c("Clinical", "Clinical", "Clinical", "Tumor", "Tumor", "Tumor")
)

ggforestplot(
  sectioned_coefs,
  facet = "section",
  striped_rows = TRUE,
  stripe_fill = "grey94",
  facet_strip_position = "right"
)

Add a summary table

ggforestplot(
  sectioned_coefs,
  striped_rows = TRUE,
  stripe_fill = "grey94"
) +
  add_forest_table()

Add a split summary table

ggforestplot(
  sectioned_coefs,
  striped_rows = TRUE,
  stripe_fill = "grey94"
) +
  add_split_table()

Learn more

Main functions

  • ggforestplot() builds the plotting panel from a data frame or supported model object.
  • add_forest_table() attaches a summary table to the left or right side of the plot.
  • add_split_table() creates a more traditional forestplot layout with table columns on both sides of the plot.
  • bind_forest_models() binds output from several models for grouped plotting.
  • as_forest_data() is the S3 conversion interface for custom coefficient data and supported fitted models.
  • forest_metadata() inspects effect-scale and source metadata.
  • tidy_forest_model() is used as a post-estimation interface for fitted models.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("ggforestplotR")

0.6.0 by Carson Richardson, 14 days ago


https://thatoneguy006.github.io/ggforestplotR/, https://github.com/thatoneguy006/ggforestplotR


Report a bug at https://github.com/thatoneguy006/ggforestplotR/issues


Browse source code at https://github.com/cran/ggforestplotR


Authors: Carson Richardson [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports ggplot2, patchwork, rlang

Suggests broom, broom.mixed, dplyr, glmmTMB, knitr, lme4, marginaleffects, nlme, rmarkdown, survival, testthat, tibble, vdiffr


Suggested by essential8.


See at CRAN