plot_forest() draws each term's estimate as a point with its confidence interval, and a
dashed line at no effect. It takes a fitted model, such as a cox_ph() fit, whose tidy()
table has the estimates, or a data frame of estimates from anywhere, such as differences in
restricted mean survival.
Usage
plot_forest(
result,
scale = NULL,
exponentiate = TRUE,
title = NULL,
term_labels = NULL,
xlab = NULL
)Arguments
- result
A fitted model, or a data frame with the columns
term,estimate, and the limitsconf_lowandconf_high(orci_lowerandci_upper).- scale
The axis scale,
"log"or"linear". The default is"log"for an exponentiated model and"linear"otherwise.- exponentiate
For a model, plot the exponentiated estimates.
- title
An optional plot title.
- term_labels
Optional display labels for the terms, as a named character vector such as
c(age = "Age (years)"). A model's factor terms are labelled with the variable and level, such ascelltype: smallcellfor the termcelltypesmallcell, and other terms keep their names.- xlab
The x axis label. The default is
"Hazard Ratio"on the log scale and"Estimate"otherwise.
Details
For a model, exponentiate = TRUE (the default) plots hazard ratios (or the model's other ratio
scale) on a log axis with the line at 1. For a data frame, the estimates are plotted as they
are, on a linear axis with the line at 0, unless scale = "log".
Examples
fit <- cox_ph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
plot_forest(fit, term_labels = c(age = "Age", sex = "Female", ph.ecog = "ECOG score"))
rmst <- data.frame(
term = c("Drug A vs placebo", "Drug B vs placebo"),
estimate = c(45, 25),
conf_low = c(-10, -20),
conf_high = c(95, 70)
)
plot_forest(rmst, xlab = "Difference in RMST (days)")