After inserting the survfit{survival}
object into
surv.plot{survSAKK}
, we can create simple survival curves,
allowing to visualize survival patterns and incorporate various
statistics in our plot.
To show some benefit of this function, NCCTG Lung Cancer Data, available in the survival package is used.
# Load required libraries
library(survSAKK)
library(survival)
# Load lung data
lung <- survival::lung
# Compute survival time in months and years
lung$time.m <- lung$time/365.25*12
lung$time.y <- lung$time/365.25
# Create survival objects
fit.lung.d <- survfit(Surv(time, status) ~ 1, data = lung)
fit.lung.m <- survfit(Surv(time.m, status) ~ 1, data = lung)
fit.lung.arm.m <- survfit(Surv(time.m, status) ~ sex, data = lung)
fit.lung.arm.y <- survfit(Surv(time.y, status) ~ sex, data = lung)
surv.plot(fit.lung.arm.m,
main = "Kaplan-Meier plot",
legend.name = c("Male", "Female"),
legend.title = "Sex",
# Size of x-axis label
xlab.cex = 1.2,
# Size of y-axis label
ylab.cex = 1.2,
# Size of axis elements
axis.cex = 0.8,
# Size of the censoirng marks
censoring.cex = 1,
# Size of the legend title
legend.title.cex = 1.2,
# Size of the risktable
risktable.cex = 0.7,
# Size of the risktable name
risktable.name.cex = 0.9
)
The parameter time.unit
can be set as follows:
"day"
, "week"
,
"month"
,"year"
.
Note the following:
The time unit in time.unit
needs to correspond to
the time unit which was used to calculate the survival object
fit
.
If time.unit = "month"
x ticks are automatically
chosen by intervals of 6 months. Whereas for
time.unit = "year"
the x ticks are chosen by intervals of
1.
Per default the risk table is provided below the Kaplan-Meier plot. It provides information about the number of patients at risk at different time points.
This section explains how to highlight a specific quantile or time point as a segment in the survival curve and how to adjust segment annotation.
# Drawing a segment line for the median, which corresponds to 0.5 quantile
surv.plot(fit.lung.arm.m,
legend.name = c("Male", "Female"),
segment.quantile = 0.5
)
The parameter segment.annotation
can take the following
values: c(x,y)
,"bottomleft"
,
"left"
, "right"
, "top"
,
"none"
Note that segment.annotation
needs to be set to “none”.
Otherwise the code does not work.
There are three options for the parameter stat
to
display statistics:
logrank
: gives the p value of the log rank test
calculated using survdiff{survival}
.
coxph
: gives the hazard ratio (HR) and its 95% CI of
the conducted Cox proportional hazards regression using
coxph{survival}
.
coxph_logrank
: is a combination of
logrank
and coxph
.
In the next example the ECOG performance status is used as stratification factor for the calculation of the statistics.
The following themes are implemented: SAKK
,
Lancet
, JCO
, WCLC
,
ESMO
We present to ways how to combine plots: via
par(mfrow=c())
and via split.screen()
par(mfrow=c())
# Plot 3
surv.plot(fit.lung.arm.y,
col = c("cadetblue2", "cadetblue"),
time.unit = "year",
stat = "coxph")
# Plot 4
surv.plot(fit.lung.arm.m,
# Cusomization of the survival plot
main = "Kaplan-Meier plot",
legend.name = c("Male", "Female"),
legend.title = "Sex",
xlab.cex = 1.2,
ylab.cex = 1.2,
axis.cex = 0.8,
censoring.cex = 1,
legend.title.cex = 1.2,
# Customization of the risktable
risktable.name.position = -9,
risktable.title.position = -9,
risktable.cex = 0.7)
split.screen()
The following examples show how a figure can be exported as png file for a report.
If a bigger font size is needed then this can be done efficiently by choosing a different size of the output file.