Description Usage Arguments Value Examples
This is a function to consistently plot aesthetically pleasing KM plots using survminer::ggsurvplot() that include risk table below and survival table within.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | km.plot(
data,
stat,
time,
arm = "arm",
x.lab = "Time (Months)",
x.time = NULL,
y.lab = "% Event-Free",
ref = as.character(levels(data2$arm)[1]),
x.max = max(data2$time),
x.by = 12,
surv.legend.labs = levels(data2$arm2),
table.legend.labs = levels(data2$arm2),
color = RColorBrewer::brewer.pal(8, "Set1"),
lty = 1,
table.font.size = 9,
y.scale = "percent",
one.sided = FALSE,
risk.table = TRUE,
table.include = TRUE,
pval.include = TRUE,
pval = NULL,
pval.loc = NULL,
size = 0.5,
risk.table.height = 0.175,
surv.plot.height = 0.825,
table.x.min = x.max/5,
table.x.max = x.max/1.5,
x.scale = 1,
surv.order = NULL,
surv.legend.title = "Arm: ",
legend.font = 9,
theme = survminer::theme_survminer(),
table.loc = "topright",
...
)
|
data |
The data. |
stat |
The survival status variable used in survfit() |
time |
The survival time variable used in survfit() |
arm |
By variable used in survfit() |
x.lab |
Label for x-axis of KM plot |
x.time |
Specific unit for the survival time variable in x-axis label, character (eg. "Days", "Months", "Years"). |
y.lab |
Label for y-axis of KM plot |
ref |
Specify reference arm for HR values in survival table. |
x.max |
Max value for the x-axis |
x.by |
By value for tick marks on the x-axis based on the scaled time variable. |
surv.legend.labs |
KM plot legend arm labels |
table.legend.labs |
Survival table arm labels |
color |
Color for KM plot lines |
lty |
Type of lines for KM plot |
table.font.size |
Font size for the survival table |
y.scale |
Scale for y-axis. Options are "default" (decimals, 0.20) and "percent" (percent, 20%) |
one.sided |
TRUE for one-sided p-value, FALSE for two-sided p-value |
risk.table |
Include risk table (TRUE/FALSE) |
table.include |
Include survival table (TRUE/FALSE) |
pval.include |
Include p-value. if TRUE and pval = NULL, logrank p-value from survfit() is included |
pval |
User specified p-value. This can be used to specify p-value used if something different than logrank is desired. Can be character or numeric. |
pval.loc |
Vector of length 2 to specify the position for the p-value if necessary. |
size |
Overall size of the plot? |
risk.table.height |
Percent of plot size taken up by the risk table. |
surv.plot.height |
Percent of plot size taken up by the KM plot. |
table.x.min |
Minimum x-axis value for the survival table if table.loc = "topright". |
table.x.max |
Maximum x-axis value for the survival table if table.loc = "bottomleft". |
x.scale |
Numeric variable to allow for scaling of the time variable. Will divide the time variable by the value given. |
surv.order |
Character vector. Allows for the display order of the variables in the legend, plot, survival table, and risk table to be specified. Must include all levels of the "arm" variable. |
surv.legend.title |
Legend title to appear at the top of the plot (i.e. "Arm: ", "Strata: '). |
legend.font |
Font size for the legend. |
theme |
Desired theme for the KM plot and risk table. |
table.loc |
Character. Specify where the survival table should go inside the plot. Currently support "topright" and "bottomleft". |
... |
Additional arguments passed onto ggsurvplot() |
This function returns a publication quality KM curve.
1 2 3 4 5 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.