plot_survfit | R Documentation |
Creates a Kaplan-Meier plot based on a survfit object
plot_survfit(fit, lwd = 1, xmax = NULL, xbreaks = NULL, ylim = NULL, ci = FALSE, cuminc = TRUE, y_percent = TRUE, split_legend_labels = TRUE, legend.title = NA, legend.position = "top")
fit |
A survfit object that we should plot |
lwd |
Line width |
xmax |
What is the upper limit of the X axis? The default will plot all data. |
xbreaks |
A numeric vector. Where should the breaks in the X axis be? The default will give ggplot's default breaks. |
ylim |
A numeric vector of length 2. Which are the Y axis limits? |
ci |
A logical scalar. Should confidence intervals be plotted? |
cuminc |
A logical scalar. Should cumulative incidence be plotted (default), or should be survival be plotted instead (cuminc = FALSE)? |
y_percent |
A logical scalar. Should the Y axis display percentages? |
split_legend_labels |
A logical scalar. Should the legends labels be split, i.e. removing the "<variable_name>=" for each stratum? |
legend.title |
What title should the legend have? By default it will take the value that was split if split_legend_labels was used; otherwise it will take the value "strata" |
legend.position |
Where should the legend be drawn? Possible answers are: "top", "bottom", "left", "right"; or if you want to skip putting a legend on the plot: "none" |
Returns a ggplot object
Daniel Lindholm
library(survsup); library(ggplot2); library(dplyr); library(survival) retinopathy %>% survfit(Surv(futime, status) ~ trt, data = .) %>% plot_survfit() retinopathy %>% survfit(Surv(futime, status) ~ trt, data = .) %>% plot_survfit(ci = TRUE, cuminc = FALSE) # Since a ggplot object is returned, # you can tweak as you wish # (in this case with multiple labels): mgus2 %>% survfit(Surv(futime, death) ~ sex, data = .) %>% plot_survfit(cuminc = FALSE) %>% nar(flip = TRUE) %>% hcl_rainbow()+ # <--- Notice + sign here! labs(title = "This is an excessively long title", subtitle = "This is a subtitle", x = "Time (days)", y = "Survival (%)", caption = "(This is a demo)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.