show_forest: Show Forest Plot

View source: R/show_forest.R

show_forestR Documentation

Show Forest Plot

Description

This is a wrapper of function ezcox, get_models and show_models. It focus on generating forest plot easily and flexibly.

Usage

show_forest(
  data,
  covariates,
  controls = NULL,
  time = "time",
  status = "status",
  merge_models = FALSE,
  model_names = NULL,
  vars_to_show = NULL,
  drop_controls = FALSE,
  add_caption = TRUE,
  point_size = 3,
  point_shape = 15,
  color = "red",
  banded = TRUE,
  headings = list(variable = "Variable", n = "N", measure = "Hazard ratio", ci = NULL, p
    = "p"),
  model_dir = file.path(tempdir(), "ezcox"),
  verbose = TRUE,
  ...
)

Arguments

data

a data.frame containing variables, time and os status.

covariates

a character vector optionally listing the variables to include in the plot (defaults to all variables).

controls

column names specifying controls. The names with pattern "*:|()" will be treated as interaction/combination term, please make sure all column names in data are valid R variable names.

time

column name specifying time, default is 'time'.

status

column name specifying event status, default is 'status'.

merge_models

if 'TRUE', merge all models and keep the plot tight.

model_names

model names to show when merge_models=TRUE.

vars_to_show

default is NULL, show all variables (including controls). You can use this to choose variables to show, but remember, the models have not been changed.

drop_controls

works when covariates=NULL and models is a ezcox_models, if TRUE, it removes control variables automatically.

add_caption

if TRUE, add caption to the plot.

point_size

size of point.

point_shape

shape value of point.

color

color for point and segment.

banded

if TRUE (default), create banded background color.

headings

a list for setting the heading text.

model_dir

a path for storing model results.

verbose

if TRUE, print extra info.

...

other arguments passing to forestmodel::forest_model().

Value

a ggplot object

Examples

library(survival)
show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age")
show_forest(lung, covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE)
show_forest(lung,
  covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE,
  drop_controls = TRUE
)
p <- show_forest(lung,
  covariates = c("sex", "ph.ecog"), controls = "age", merge_models = TRUE,
  vars_to_show = "sex"
)
p

ezcox documentation built on May 31, 2023, 7:49 p.m.