| kmplot | R Documentation |
Draws Kaplan-Meier curves in a publication style: step curves with censoring marks, the legend inside the panel, an optional log-rank p-value, and a number-at-risk table coloured by group under the plot. Besides the survival function, it draws the risk function, the cumulative hazard, the complementary log-log diagnostic of proportional hazards, and cumulative incidence under competing risks. A fitted survalis model adds its predicted or covariate-adjusted curves, dashed, over the Kaplan-Meier curves.
kmplot(
formula,
data,
type = c("survival", "risk", "cumhaz", "cloglog"),
event = NULL,
model = NULL,
model.curve = c("predicted", "adjusted"),
title = NULL,
xlab = "Time",
ylab = NULL,
breaks = NULL,
pval = TRUE,
risk.table = TRUE,
conf.int = FALSE,
colors = NULL,
legend.pos = NULL,
pval.pos = NULL,
base_size = 10
)
formula |
A survival formula such as |
data |
A data frame holding the variables in |
type |
What to draw: |
event |
Competing-risks data only: the event whose cumulative
incidence is drawn. |
model |
Optional fitted model from |
model.curve |
|
title |
Panel title, for example |
xlab, ylab |
Axis labels. |
breaks |
Time breaks for the x axis and the risk table. |
pval |
Log-rank p-value when there are two or more groups: |
risk.table |
Logical; draw the number-at-risk table (default |
conf.int |
Logical; draw pointwise 95% confidence bands (default
|
colors |
Group colours. |
legend.pos |
Legend position inside the panel, |
pval.pos |
P-value position, |
base_size |
Base font size (default |
A 'patchwork' object (curve over risk table) when the risk table is
drawn, otherwise a 'ggplot2' object. Panels combine with patchwork
operators, for example kmplot(...) | kmplot(...).
kmplot(Surv(time, status) ~ trt, data = veteran, risk.table = FALSE)
kmplot(Surv(time, status) ~ trt, data = veteran, type = "cloglog")
# Competing risks: progression versus death without progression
d <- survival::mgus2
d$etime <- ifelse(d$pstat == 1, d$ptime, d$futime)
d$event <- factor(ifelse(d$pstat == 1, 1, 2 * d$death), 0:2,
c("censored", "progression", "death"))
kmplot(Surv(etime, event) ~ sex, data = d, risk.table = FALSE)
if (requireNamespace("patchwork", quietly = TRUE)) {
kmplot(Surv(time, status) ~ trt, data = veteran,
title = "A. Overall survival", xlab = "Days",
breaks = seq(0, 1000, 200))
# Covariate-adjusted curves from a Cox model, over the Kaplan-Meier curves
m <- fit(Surv(time, status) ~ trt + karno + age, data = veteran,
model = "coxph")
kmplot(Surv(time, status) ~ trt, data = veteran, model = m,
model.curve = "adjusted", breaks = seq(0, 1000, 200))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.