Data & Functions
Survival Plot


Data


# Libraries
library(survminer)
library(survival)
  
# Reformate the data table with the variables we'll use
lung <- lung[,c("time","status","sex")]


lung format :

A data frame with 228 observations on the following 10 variables :
time Survival time in days
status Censoring status; 1=censored, 2=dead
Sex Patient sex; Male=1 Female=2




#Head of dataset
knitr::kable(head(lung,8), align = "l")
time status sex
306 2 1
455 2 1
1010 1 1
210 2 1
883 2 1
1022 1 1
310 2 2
361 2 2

ggsurvplot function


ggsurvplot(
fit, A survfit object
data = NULL, Dataset used to fit survival curves
fun = NULL, An arbitrary function defining a transformation of the survival curve
color = NULL, Color to be used for the survival curves
palette = NULL, The color palette to be used
linetype = 1, Line types. Allowed values includes : i) “strata” for changing linetypes by strata (i.e. groups); ii) a numeric vector (e.g., c(1, 2)) or a character vector c(“solid”, “dashed”)
conf.int = FALSE, Logical value. If TRUE, plots confidence interval
pval = FALSE, Logical value, a numeric or a string. If logical and TRUE, the p-value is added on the plot. If numeric, than the computet p-value is substituted with the one passed with this parameter. If character, then the customized string appears on the plot
pval.coord = NULL, numeric vector, of length 2, specifying the x and y coordinates of the p-value
pval.method = FALSE, Whether to add a text with the test name used for calculating the pvalue
test.for.trend = FALSE, Logical value. If TRUE, returns the test for trend p-values
surv.median.line = "none", Character vector for drawing a horizontal/vertical line at median survival. Allowed values include one of c(“none”, “hv”, “h”, “v”). v: vertical, h:horizontal
risk.table = FALSE, TRUE or FALSE specifying whether to show or not the risk table or ‘absolute’, ‘percentage’, ‘nrisk_cumcensor’, ‘nrisk_cumevents’
risk.table.fontsize, Font size to be used for the risk table and the cumulative events table
cumevents = FALSE, Logical value specifying whether to show or not the table of the cumulative number of events
cumcensor = FALSE, Logical value specifying whether to show or not the table of the cumulative number of censoring
tables.height = 0.25, Numeric value (in [0 - 1]) specifying the general height of all tables under the main survival plot
group.by = NULL, A character vector containing the name of grouping variables
facet.by = NULL, A character vector containing the name of grouping variables to facet the survival curves into multiple panels
add.all = FALSE, Logical value. If TRUE, add the survival curve of pooled patients onto the main plot
combine = FALSE, Logical value. If TRUE, combine a list survfit objects on the same plot
break.time.by = NULL, numeric value controlling time axis breaks
ggtheme = theme_survminer(), ggplot2 theme name (see ggplot2 page)
tables.theme = ggtheme, ggplot2 theme name (see ggsurvtheme)
... )




Contact

This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.

SBIM