Learn R Programming

utile.visuals (version 0.3.3)

ggrisktable: Create a ggplot2 table showing the number at risk

Description

A simple wrapper function which calculates the numbers at risk for a survival model and a given set of time points then creates a ggplot2 table with them.

Usage

ggrisktable(
  fit = NULL,
  times = NULL,
  text.color = "black",
  strata.order = NULL
)

Value

An unformatted ggplot2 table showing the number at risk.

Arguments

fit

Required. survival::survfit() object.

times

Required. Numeric. One or more time points to calculate the number at risk for.

text.color

Optional. Character. Color of text within table. Defaults to 'black'.

strata.order

Optional. Character. Ordered names of strata factor levels.

Examples

Run this code
library(survival)

fit <- survfit(Surv(time, status) ~ trt, data = diabetic)

ggrisktable(
   fit = fit,
   times = c(0, 10, 20, 30, 40, 50),
   strata.order = c('0', '1')
) + theme_risk()

Run the code above in your browser using DataLab