survplot | R Documentation |
Plot Kaplan-Meier survival curves, automatically generate a key for each strata, and calculate and display hazard ratio if there are exactly two strata. Optionally, indicate the number-at-risk below the main plot.
survplot(x, data = NULL, subset = NULL,
snames, stitle,
col, lty, lwd,
show.nrisk = TRUE, color.nrisk = TRUE,
hr.pos = 'topright', legend.pos = 'bottomleft', ...)
x |
A formula, as would be appropriate for |
data , subset |
Arguments passed to |
snames |
Names for each stratum, to be used in the legend. If missing, these are inferred from the data. |
stitle |
Title for the strata legend. If missing, this is inferred from |
col , lty , lwd |
Colors, line type, and line width for each stratum (optional). |
show.nrisk |
Indicate the number-at-risk for each stratum below the plot? |
color.nrisk |
Color the number-at-risk to match the plot? |
hr.pos |
Where to put the hazard ratio information, or NA to omit (see |
legend.pos |
Where to put the legend, or NA to omit (see |
... |
Further parameters sent to |
This function was written and documented by Aron Charles Eklund in his package survplot version 0.0.7.
Hazard ratio (and 95% confidence intervals) and logrank P are calculated and displayed if there are exactly two groups.
If there is exactly one group (no stratification), the legend is omitted.
If there are exactly two groups, a character vector with the HR and P value is returned invisibly.
The lower figure margin is increased if the number-at-risk is displayed.
Aron Charles Eklund (survplot version 0.0.7)
nrisk
library(survival)
surv <- Surv(colon$time / 365, colon$status)
survplot(surv ~ rx,
data = colon,
lty = 1:3,
main = 'Patients stratified by treatment',
xlab = 'Time (Years)')
survplot(surv ~ colon$sex,
main = 'Patients stratified by sex',
xlab = 'Time (Years)',
snames = c('F', 'M'),
stitle = 'Gender')
survplot(surv ~ sex,
data = colon,
subset = colon$surg == 1)
## Example without stratification
survplot(surv ~ 1, data = colon)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.