kmplot: kmplot

View source: R/plot.R

kmplotR Documentation

kmplot

Description

Make a Kaplan-Meier plot of a data set.

Usage

kmplot(
  x,
  ...,
  relevel = FALSE,
  col = NULL,
  plot = TRUE,
  xlim = NULL,
  ylim = NULL,
  xaxis.at = NULL,
  xlab = NULL,
  ylab = NULL,
  lr_test = TRUE,
  test_details = TRUE,
  median = TRUE,
  atrisk = TRUE,
  mark.time = TRUE,
  title = NULL,
  legend = TRUE
)

## S3 method for class 'kmdata'
plot(
  x,
  ...,
  relevel = FALSE,
  col = NULL,
  plot = TRUE,
  xlim = NULL,
  ylim = NULL,
  xaxis.at = NULL,
  xlab = NULL,
  ylab = NULL,
  lr_test = TRUE,
  test_details = TRUE,
  median = TRUE,
  atrisk = TRUE,
  mark.time = TRUE,
  title = NULL,
  legend = TRUE
)

Arguments

x

a data set of class "kmdata", i.e., one of the data sets in the kmdata package; alternatively, a data frame with columns "time", "event", and "arm"

...

additional arguments passed to plot.survfit or further to plot.default or par

relevel

logical; if TRUE, group order is reversed; by default, the arms are in alphabetical order which may not be desired for some placebo or control arms

col

a vector of colors for the survival curves (recycled for at-risk table, medians, and legend)

plot

logical; if TRUE, a KM figure is drawn

xlim, ylim

x- and y-axis limits

xaxis.at

x-axis positions of ticks and at-risk table

xlab, ylab

the x- and y-axis labels

lr_test

logical; if TRUE, log-rank test is shown in upper right corner of figure

test_details

logical; if TRUE, test statistic and degrees of freedom are added with p-value for log-rank test

median

logical; if TRUE, the medians for each curve is added

atrisk

logical; if TRUE, an at-risk table is drawn below plot

mark.time

passed to plot.survfit

title

optional title for plot; default is attr(data, 'title')

legend

logical; if TRUE, a legend for the arms, total events, and hazard ratios is added

Examples

kmplot(ATTENTION_2A)

kmplot(
  ATTENTION_2A,
  relevel = TRUE, median = FALSE,
  col = 3:4, xaxis.at = 0:4 * 6
)

## or equivalently with ?survival::plot.survfit
s <- survfit(Surv(time, event) ~ arm, ATTENTION_2A)
plot(s, col = 1:2, mark.time = TRUE)


## kmplot can be used generically given the proper data structure
dat <- data.frame(time = aml$time, event = aml$status, arm = aml$x)
kmplot(dat)


raredd/kmdata documentation built on June 15, 2025, 9:33 a.m.