forest_plot: Forest Plot

Description Usage Arguments Value Examples

View source: R/forest_plot.R

Description

This function creates the data for and plots a forest plot comparing hazard rates for categorical variables by a 2 level by variable.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
forest_plot(
  data,
  stat,
  time,
  byvar,
  covars,
  ref = as.character(levels(data2$arm)[1]),
  labels = NULL,
  graph.pos = 3,
  xaxis.breaks = 0.25,
  title = "Hazard Rates",
  x.lab = "Hazard Ratios",
  plot.include = TRUE,
  x.max = max(values$upper, na.rm = TRUE),
  ...
)

Arguments

data

A dataset containing the necessary survival variables (event, time, other covariables).

stat

The event survival variable, numeric, with 1 coded as an event and 0 a censor.

time

The time survival variable, numeric.

byvar

The by variable with 2 distinct levels.

covars

A vector of categorical covariates that are desired for analysis.

ref

Reference by variable level (optional). Use this if specific by variable level is desired as the reference.

labels

An optional vector, soon to be list, of labels for the covariates in the 'covars' variable. Currently must be the same length as the 'covars' vector.

graph.pos

Column position for the graph.

xaxis.breaks

Distance between the x-axis breaks of the forest plot.

title

Title for the plot.

x.lab

Label for x-axis of plot.

plot.include

Logical to have plot return from function call.

x.max

Max value for x-axis. CI bands for intervals that pass this value will have an arrow on the right indicating a continuing band.

...

Additional arguments for the 'forestplot' function.

Value

This function returns a list of the forestplot produced and tables necessary to reproduce that plot.

Examples

1
2
3
4
5
6
7
8
9
library(arsenal)
data(mockstudy)
mockstudy %>%
 mutate(fu.stat = fu.stat - 1) %>%
 filter(arm != "A: IFL" & age.ord != "10-19" & race != "Other") %>%
 forest_plot(data = ., stat = "fu.stat", time = "fu.time", byvar = "arm", 
             covars = c("sex", "age.ord"), title = "Overall Survival", 
             labels = c("Gender", "Age Groups"), 
             xaxis.breaks = .5)

sjacobson94/clinicaltrials documentation built on Oct. 27, 2020, 6:43 p.m.