kmplot | R Documentation |
Creates a Kaplan Meier plot with the option of risk and cumulative event tables. This is essentially my favorite KM plot using the survminer
package. Default is my favorite settings.
kmplot( df, km, colors, conf.int = T, p.val = F, break.int = 6, risk.table = "nrisk_cumcensor", cumevents = T, lgd = "top", ttl = "", textsize = 4, ylab = "", xlab = "", height = 10, surv.median.line = "hv", labs, text.size = 14, title.size = 16, legend.size = 12 )
df |
a data set used to fit survival curves |
km |
a survfit object |
colors |
a vector of colors for survival curves, length equal to number of curves. |
conf.int |
logical. if TRUE, plots confidence interval. Default is TRUE. |
p.val |
logical. if TRUE, adds p-value to the plot. Default is FALSE. |
break.int |
numeric. controls when time axis ticks are presented. Defaults to 6 units (often used for 6 months). |
risk.table |
logical, or string. allowed values are those allowed in the |
cumevents |
logical. logical value specifying whether to show or not the table of the cumulative number of events. Default is TRUE. |
lgd |
character specifying the legend location. Default is "top" |
ttl |
legend title |
textsize |
text size. default is 4 |
ylab |
y-axis label |
xlab |
x-axis label |
height |
height of the survival plot. Default is 10. Ignored when risk.table = FALSE |
surv.median.line |
a character for how median survival lines should be drawn. Allowed values include one of c("none", "hv", "h", "v"). v: vertical, h:horizontal. |
labs |
legend labels. If not specified, will use strata names. |
text.size |
text size for axis text |
title.size |
text size for plot titles |
legend.size |
text size for legend |
kmplot(df = lung, km =survfit(Surv(time, status) ~ sex, data = lung), surv.median.line = "hv", break.int = 365) survObj <- survfit(Surv(time, status) ~ ph.ecog, data = lung) kmplot(df = lung, km = survObj, surv.median.line = "hv", break.int = 180, colors = c("red", "blue", "orange", "black"), labs = gsub("ph.ecog=", "", attr(survObj$strata, "names")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.