Creates a Kaplan-Meier plot with at risk tables below.
Based on the original packge by Michael Way(https://github.com/michaelway/ggkm), I added some minor changes that allow users to:
1) add hazards ratio (HR) and CI for HR to the plot.
2) do the incidence plot instead of KM plot.
3) plot with black and white, sometimes required by a journal.
4) change the aspect ratio of the plot.
ggkm(sfit, table = FALSE, xlabs = "Time-to-event", ylabs = "Survival (%)",
xlims = c(0, max(sfit$time)), ylims = c(0, 1), ystratalabs = names(sfit$strata),
ystrataname = "Strata", timeby = signif(max(sfit$time)/7, 1), main = "",
pval = FALSE, pvposition = c(0.3, 0.6), marks = TRUE, shape = 3,
legend = TRUE, legendposition = c(0.85, 0.8), ci = FALSE, subs = NULL,
linecols = "Set1", dashed = FALSE, aspectRatio = 0.7143, black = FALSE,
data = NULL, HR = FALSE, incid = FALSE, pvaltxt = NULL, hrtxt = NULL, ...)
a survfit object
numeric: control the granularity along the time-axis; defaults to 7 time-points. Default = signif(max(sfit$time)/7, 1)
plot title
logical: add the pvalue to the plot?
logical: should censoring marks be added?
= NULL,
logical: Create a table graphic below the K-M plot, indicating at-risk numbers?
x-axis label
y-axis label
numeric: list of min and max for x-axis. Default = c(0,max(sfit$time))
numeric: list of min and max for y-axis. Default = c(0,1)
character list. A list of names for each strata. Default = names(sfit$strata)
The legend name. Default = "Strata"
what shape should the censoring marks be, default is a vertical line
logical. should a legend be added to the plot?
numeric. x, y position of the legend if plotted. Default=c(0.85,0.8)
logical. Should confidence intervals be plotted. Default = FALSE
Character. Colour brewer pallettes too colour lines. Default ="Set1",
logical. Should a variety of linetypes be used to identify lines. Default = FALSE
position for the p-value, default = c(0.3, 0.6).
text for the p-value, default is NULL.
add aspect ratio of the plot, default is 0.7134.
black and white plot, default is FALSE.
data set for the plot, could be useful when one need HR on the plot.
plot incidence curve instead of KM curve, default is FALSE.
add hazards ratio to the plot, default is FALSE.
text for the hazards ratio, default is NULL.
additional arguments to be passed to the ggkm function.
Michael Way(https://github.com/michaelway/ggkm), heavily modified version of a script created by Abhijit Dasgupta with contributions by Gil Tomas. https://statbandit.wordpress.com/2011/03/08/an-enhanced-kaplan-meier-plot/ Michael have packaged this function, added functions to namespace and included a range of new parameters. Bingshu Chen added more options to the plot (see above) and made minor corrections of the R code and the R docments files to pass the R CMD check.
library(survival)
data(colon)
fit <- survfit(Surv(time,status)~rx, data=colon)
# ggkm(fit, timeby=500)
Run the code above in your browser using DataLab