Learn R Programming

survMisc (version 0.4.4)

autoplot.survfit: Generate a ggplot for a survfit object

Description

Uses ggplot2 to render a table showing the number of subjects at risk per time period and survival curves (Kaplan-Meier plot) and to render

Usage

## S3 method for class 'survfit':
autoplot(object, ..., xLab = "Time", yLab = "Survival",
  title = "Marks show times with censoring", titleSize = 15,
  axisTitleSize = 15, axisLabSize = 10, survLineSize = 0.5,
  type = c("single", "CI", "fill"), palette = c("Dark2", "Set2", "Accent",
  "Paired", "Pastel1", "Pastel2", "Set1", "Set3"), jitter = c("none",
  "noEvents", "all"), censShape = 3, censSize = 5, legend = TRUE,
  legLabs = NULL, legTitle = "Strata", legTitleSize = 10,
  legLabSize = 10, alpha = 0.05, CIline = 10, fillLineSize = 0.05,
  pVal = FALSE, sigP = 1, pX = 0.1, pY = 0.1, timeTicks = c("major",
  "minor"), tabTitle = "Number at risk by time", tabTitleSize = 15,
  tabLabSize = 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.
titleSize
Title size for survival plot.
axisTitleSize
Title size for axes.
axisLabSize
Title size for label axes.
survLineSize
Survival line size.
type
Type of plot. The default, type="single", plots single lines.
  • Iftype="CI"will add lines indicating confidence intervals (taken fromupperandlowervalues ofsurvfitobject). Highe
palette
Options are taken from http://colorbrewer2.org/{color_brewer}.
  • palette="Dark2"(the default) is recommended forsingleorCIplots.
  • palette="Set2"is recommended forfill
jitter
By default, jitter="none".
  • Ifjitter="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 se
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.
legTitleSize
Title size for legend.
legLabSize
Legend labels width and height.
alpha
Alpha, the transparency of lines indicating confidence intervals or filled rectangles. Should be in the range $0$ to $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 censShape=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$ to $3$.
pX
Location of $p$ value on $x$ axis. Should be in the range of $0$ to $1$. The location is relative to the maximum observed time. E.g. pX = 0.5 will place it half-way along the $x$-axis.
pY
Location of $p$ value on $y$ axis. Should be in the range of $0 - 1$, as above
timeTicks
Numbers to mark on the survival plot and table.
  • IftimeTicks="major"(the default) only the major$x$-axis (time) marks from the survival plot are are labelled on the plot and table.
  • IftimeTicks="minor"
tabTitle
Table title.
tabTitleSize
Table title text size.
tabLabSize
Table legend text size.
nRiskSize
Number at risk - text size.

Value

  • A list of ggplot objects, with elements:
  • plotthe survial plot
  • tablethe table of events per time
  • This list has the additional class of tableAndPlot, allowing methods from autoplot.tableAndPlot.

Examples

Run this code
data(kidney, package="KMsurv")
s1 <- survfit(Surv(time, delta) ~ type, data=kidney)
autoplot(s1, type="fill", survLineSize=2)
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
### load all datasets from package:km.ci
d1 <- data(package="km.ci")$results[, "Item"]
data(list=d1, 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, type="fill", legend=FALSE)$plot
###
### change to user-defined colors
###
s1 <- survfit(Surv(time, delta) ~ type, data=kidney)
g1 <- autoplot(s1, type="CI", alpha=0.8, survLineSize=2)$plot
g1 + scale_colour_manual(values=c("red", "blue")) +
    scale_fill_manual(values=c("red", "blue"))

Run the code above in your browser using DataLab