plot_survfit: Plot a survfit object

View source: R/plot_survfit.R

plot_survfitR Documentation

Plot a survfit object

Description

Creates a Kaplan-Meier plot based on a survfit object

Usage

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")

Arguments

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"

Value

Returns a ggplot object

Author(s)

Daniel Lindholm

Examples


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)")

dlindholm/survsup documentation built on Jan. 12, 2023, 2:34 p.m.