survMisc (version 0.4.2)

autoplot: Generate a ggplot for survfit object

Description

Uses ggplot2 to plot survival curves (Kaplan-Meier plot)

Usage

## S3 method for class 'survfit':
autoplot (object, ..., alpha = 0.5,
    shape = 3, xlab = "Time", ylab = "Survival",
    title = "Marks show times with censoring",
    legendLabs = NULL, CI = FALSE, bands = FALSE,
    pval = FALSE, plotTable = FALSE, divideTime = 1,
    returnTable = FALSE)

Arguments

object
An object of class survfit
...
Additional arguments
alpha
Transparency to use for confidence intervals or bands
shape
Shape of marks to indicate censored onservations. Default is 3 which gives vertical ticks. Use 10 for circular marks.
xlab
Label for x axis
ylab
Label for y axis
title
Title for graph
legendLabs
Legend labels. These can be used to replace the names of the strata from the fit. Should be given in the same order as those strata.
CI
Include confidence intervals (plotted as lines). These are taken from the survfit object.
bands
Include confidence bands (plotted as ribbons i.e. filled and joined by diagonal lines rather than steps)
pval
Add $p$ value from log-rank test to lower left of plot
plotTable
Add table below plot. This contains one row for each time increment for each strata, giving the number at risk at that time.
divideTime
Divide time by this number to give time increments. A larger number may be preferable with large data sets to avoid crowding.
returnTable
Return data.frame used for table.

Value

  • A ggplot and optionally a data.frame as above.

Examples

Run this code
data(kidney, package="KMsurv")
s1 <- survfit(Surv(time=time, event=delta) ~ type, data=kidney)
autoplot(s1)
autoplot(s1, CI=TRUE, pval=TRUE, plotTable=TRUE, divideTime=5,
 legendLabs=c("surgical", "percutaneous"),
 title="Time to infection following catheter placement \n
   by type of catheter, for dialysis patients")
s1 <- survfit(Surv(time=time, event=delta) ~ 1, data=kidney)
autoplot(s1)
data(rectum.dat, package="km.ci")
s1 <- survfit(Surv(time, status) ~ 1, data=rectum.dat)
### change confidence intervals to log Equal-Precision confidence bands
km.ci::km.ci(s1, method="logep")
autoplot(s1, bands=TRUE)

Run the code above in your browser using DataLab