survMisc (version 0.5.6)

autoplotTen: Generate a ggplot for a survfit or ten object

Description

Generate a ggplot for a survfit or ten object

Usage

autoplot(object, ...)

# S3 method for ten autoplot( object, ..., title = "Marks show times with censoring", type = c("single", "CI", "fill"), alpha = 0.05, ciLine = 10, censShape = 3, palette = c("Dark2", "Set2", "Accent", "Paired", "Pastel1", "Pastel2", "Set1", "Set3"), jitter = c("none", "noEvents", "all"), tabTitle = "Number at risk by time", xLab = "Time", timeTicks = c("major", "minor", "days", "months", "custom"), times = NULL, yLab = "Survival", yScale = c("perc", "frac"), legend = TRUE, legTitle = "Group", legLabs = NULL, legOrd = NULL, titleSize = 15, axisTitleSize = 15, axisLabSize = 10, survLineSize = 0.5, censSize = 5, legTitleSize = 10, legLabSize = 10, fillLineSize = 0.05, tabTitleSize = 15, tabLabSize = 5, nRiskSize = 5 )

# S3 method for stratTen autoplot( object, ..., title = NULL, type = c("single", "CI", "fill"), alpha = 0.05, ciLine = 10, censShape = 3, palette = c("Dark2", "Set2", "Accent", "Paired", "Pastel1", "Pastel2", "Set1", "Set3"), jitter = c("none", "noEvents", "all"), tabTitle = "Number at risk by time", xLab = "Time", timeTicks = c("major", "minor", "days", "months", "custom"), times = NULL, yLab = "Survival", yScale = c("perc", "frac"), legend = TRUE, legTitle = "Group", legLabs = NULL, legOrd = NULL, titleSize = 15, axisTitleSize = 15, axisLabSize = 10, survLineSize = 0.5, censSize = 5, legTitleSize = 10, legLabSize = 10, fillLineSize = 0.05, tabTitleSize = 15, tabLabSize = 5, nRiskSize = 5 )

# S3 method for survfit autoplot( object, ..., title = "Marks show times with censoring", type = c("single", "CI", "fill"), alpha = 0.05, ciLine = 10, censShape = 3, palette = c("Dark2", "Set2", "Accent", "Paired", "Pastel1", "Pastel2", "Set1", "Set3"), jitter = c("none", "noEvents", "all"), tabTitle = "Number at risk by time", xLab = "Time", timeTicks = c("major", "minor", "weeks", "months", "custom"), times = NULL, yLab = "Survival", yScale = c("perc", "frac"), legend = TRUE, legLabs = NULL, legOrd = NULL, legTitle = "Group", titleSize = 15, axisTitleSize = 15, axisLabSize = 10, survLineSize = 0.5, censSize = 5, legTitleSize = 10, legLabSize = 10, fillLineSize = 0.05, tabTitleSize = 15, tabLabSize = 5, nRiskSize = 5, pVal = FALSE, sigP = 1, pX = 0.1, pY = 0.1 )

Arguments

object

An object of class survfit, ten or stratTen.

...

Additional arguments (not implemented).

title

Title for survival plot.

type

type="single" (the default) plots single lines.

type="CI"

Adds lines indicating confidence intervals (taken from upper and lower values of survfit object). Higher values of alpha (opacity) are recommended for this, e.g. alpha=0.8.

type="fill"

Adds filled rectangles from the survival lines to the confidence intervals above.

alpha

Opacity of lines indicating confidence intervals or filled rectangles. Should be in range \(0-1\). Lower = more transparent. Larger values e.g. alpha=0.7 are recommended for confidence intervals.

ciLine

Confidence interval line type. See 'line type specification' in ?graphics::par

censShape

Shape of marks to indicate censored onservations. Default is 3 which gives vertical ticks. Use censShape=10 for circular marks. See ?graphics::points

palette

Options are taken from color_brewer.

  • palette="Dark2" (the default) is recommended for single or CI plots.

  • palette="Set2" is recommended for type="fill" plots.

jitter

By default, jitter="none".

  • 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="all" add some vertical and horizontal noise to all survival lines. This can prevent overlapping of lines for censoring.

tabTitle

Table title. --Axis arguments:

xLab

Label for \(x\) axis on survival plot.

timeTicks

Numbers to mark on the \(x\) axis of the survival plot and the table.

"major"

(the default) only the major \(x\)-axis (time) marks from the survival plot are are labelled on the plot and table.

"minor"

minor axis marks are labelled instead.

"days"

scale is \(0, 7, 14, ..., t_{max}\)

"months"

scale is \(0, 12,, 24, ..., t_{max}\)

"custom"

scale is given by times below

times

Vector of custom times to use for \(x\) axis.

yLab

Label for \(y\) axis on survival plot.

yScale

Display for point on \(y\) axis:

"perc"

Displays as percentages.

"frac"

Displays as fractions e.g. \(0, 0.1, 0.2, ..., 1.0.\)

--Legend arguments:

legend

If legend=FALSE, no legends will be produced for the plot or table.

legTitle

Legend title.

legLabs

Legend labels. These can be used to replace the names of the covariate groups ('strata' in the case of a survfit object). Should be given in the same order as those strata.

legOrd

Legend order. --Size arguments: Size arguments are passed to ggplot2::element_text(size=).

titleSize

Title size for survival plot.

axisTitleSize

Title size for axes.

axisLabSize

Title size for labels on axes.

survLineSize

Survival line size.

censSize

Size of marks to indicate censored onservations.

legTitleSize

Title size for legend.

legLabSize

Legend labels width and height.

fillLineSize

Line size surrouding filled boxes.

tabTitleSize

Table title text size.

tabLabSize

Table legend text size.

nRiskSize

Number at risk - text size. --Arguments for autoplot.survfit only:

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 - 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 the range of \(0 - 1\), as above.

See Also

?ggplot2::ggplot_build

Examples

Run this code
# NOT RUN {
## examples are slow to run; see vignette for output from these
# }
# NOT RUN {
### autoplot.ten
data("kidney", package="KMsurv")
t1 <- ten(survfit(Surv(time, delta) ~ type, data=kidney))
autoplot(t1)
autoplot(t1, type="fill", survLineSize=2, jitter="all")
autoplot(t1, timeTicks="months", 
 type="CI", jitter="all",
 legLabs=c("surgical", "percutaneous"),
 title="Time to infection following catheter placement \n
   by type of catheter, for dialysis patients",
 titleSize=10, censSize=2)$plot
t2 <- ten(survfit(Surv(time=time, event=delta) ~ 1, data=kidney))
autoplot(t2, legLabs="")$plot
autoplot(t2, legend=FALSE)
data("rectum.dat", package="km.ci")
t3 <- ten(survfit(Surv(time, status) ~ 1, data=rectum.dat))
## change confidence intervals to log Equal-Precision confidence bands
ci(t3, how="nair", tL=1, tU=40)
autoplot(t3, type="fill", legend=FALSE)$plot
## manually changing the output
t4 <- ten(survfit(Surv(time, delta) ~ type, data=kidney))
(a4 <- autoplot(t4, type="CI", alpha=0.8, survLineSize=2)$plot)
## change default colors
a4 + list(ggplot2::scale_color_manual(values=c("red", "blue")),
          ggplot2::scale_fill_manual(values=c("red", "blue")))
## change limits of y-axis
suppressMessages(a4 + ggplot2::scale_y_continuous(limits=c(0, 1)))
# }
# NOT RUN {
data("pbc", package="survival")
t1 <- ten(Surv(time, status==2) ~ trt + strata(edema), data=pbc, abbNames=FALSE)
autoplot(t1)
# }
# NOT RUN {
### autoplot.survfit
# }
# NOT RUN {
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
data(rectum.dat, package="km.ci")
s1 <- survfit(Surv(time, status) ~ 1, data=rectum.dat)
## change confidence intervals to log Equal-Precision confidence bands
if (require("km.ci")) {
 km.ci::km.ci(s1, method="logep")
 autoplot(s1, type="fill", legend=FALSE)$plot
}
## manually changing the output
s1 <- survfit(Surv(time, delta) ~ type, data=kidney)
g1 <- autoplot(s1, type="CI", alpha=0.8, survLineSize=2)$plot
## change default colors
g1 + ggplot2::scale_colour_manual(values=c("red", "blue")) +
    ggplot2::scale_fill_manual(values=c("red", "blue"))
## change limits of y-axis
g1 + ggplot2::scale_y_continuous(limits=c(0, 1))
# }

Run the code above in your browser using DataCamp Workspace