Learn R Programming

survMisc (version 0.4.2)

autoplot.survfit: Generate a ggplot for survfit object

Description

Uses ggplot2 to generate survival curves (Kaplan-Meier plot) and a table showing no. of events per time period

Usage

## S3 method for class 'survfit':
autoplot(object, ..., xlab = "Time",
    ylab = "Survival",
    title = "Marks show times with censoring",
    titTextSize = 15, axisTitSize = 15, axisLabSize = 10,
    survSize = 0.5, type = c("single", "CI", "fill"),
    palette = c("Dark2", "Set2", "Accent", "Paired", "Pastel1", "Set1", "Set3"),
    jitter = c("none", "noEvents", "all"), censShape = 3,
    censSize = 5, legend = TRUE, legLabs = NULL,
    legTitle = "Strata", legTextSize = 10, legSize = 2,
    alpha = 0.05, CIline = 10, fillLineSize = 0.05,
    pval = FALSE, sigP = 1, pX = 0.1, pY = 0.1,
    tabTime = c("major", "minor"),
    tabTitle = "Number at risk by time",
    tabTitTextSize = 15, tabLegTextSize = 5, nRiskSize = 5)

Arguments

object
An object of class survfit
...
Additional arguments (not implemented)
xlab
Label for x axis on survival plot
ylab
Label for y axis on survival plot
title
Title for survival plot
titTextSize
Title size for survival plot
axisTitSize
Title size for axes
axisLabSize
Title size for label axes
survSize
Survival line size
type
If type="single" (the default), plots single lines. If type="CI" will add lines indicating confidence intervals (taken from upper and lower values of survfit object. Higher val
palette
Options are taken from http://colorbrewer2.org/{color_brewer}. palette="Dark2" (the default) is recommended for ##' single or CI plots. palette="Set2" is recommended for fill
jitter
If jitter="noEvents", adds some random, positive noise to survival lines with no events (i.e. all observations censored). This will bring them just above 1 on the y-axis, making them easier to see separately. If jitter="al
legend
If legend=FALSE, no legends will be produced for the plot or table
legLabs
These can be used to replace the names of the strata from the fit. Should be given in the same order as those strata
legTitle
Title for legend
legTextSize
Title size for legend
legSize
Legend (key) width and height
alpha
Alpha, transparency of lines indicating confidence intervals or filled rectangles. Should be in range $0-1$. Larger values e.g. alpha=0.7 are recommended for confidence intervals
censShape
Shape of marks to indicate censored onservations. Default is 3 which gives vertical ticks Use 10 for circular marks
censSize
Size of marks to indicate censored onservations
CIline
Confidence interval line type
fillLineSize
Line size surrouding filled boxes
pval
If pval=TRUE, adds $p$ value from log-rank test to plot
sigP
No. of significant digits to display in $p$ value. Typically $1-3$
pX
Location of $p$ value on x axis. Should be in range of $0 - 1$, where value is to be placed relative to the maximum observed time. E.g. pX = 0.5 will place it half-way along x-axis
pY
Location of $p$ value on y axis. Should be in range of $0 - 1$, as above
tabTime
If tabTime="major" this will use the major x-axis (time) marks from the survival plot. If tabTime="minor", minor axis marks are used instead
tabTitle
Table title
tabTitTextSize
Table title text size
tabLegTextSize
Table legend text size
nRiskSize
No. at risk - text size

Value

  • A list of ggplot objects, with elments plot, the survial plot and table the table of events per time. This list has the additional class of tableAndPlot, allowing methods from autoplot.tableAndPlot. Further modifications may be made to the objects in the list if desired.

Examples

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

Run the code above in your browser using DataLab