nt_km: Kaplan-Meier plot

View source: R/kaplan_meier.R

nt_kmR Documentation

Kaplan-Meier plot

Description

Plot Kaplan-Meier curves for several variables.

Usage

nt_km(
  data,
  time,
  status,
  labels = NULL,
  xlab = "Time",
  ylab = "Survival",
  base_size = 20,
  time_points = NULL,
  risk_table = TRUE,
  survival_table = NULL,
  save = FALSE,
  fig_height = 5,
  fig_width = 7,
  std_fun = std_km,
  std_fun_group = std_km_group,
  std_survival_table = std_get_survival_table,
  format = TRUE,
  digits = 2,
  file = "survival",
  where = NULL,
  ...
)

Arguments

data

a data frame with the variables.

time

a data frame with the time to event variable.

status

a data frame with the indicator associated to events.

labels

a list of labels with components given by their variable names.

xlab

a character value specifying the x axis label.

ylab

a character value specifying the y axis label.

time_points

a numeric vector of time points to evaluate the survival curves.

risk_table

a logical value indicating whether the risk table should be calculated.

save

a logical value indicating whether the output should be saved as a jpeg file.

fig_height

a numeric value indicating the height (in) of the file.

fig_width

a numeric value indicating the width (in) of the file.

std_fun

a function to plot a barplot when group = NULL. It must follow the same structure of std_barplot.

std_fun_group

a function to plot a dotplot when group is provided. It must follow the same structure of std_barplot_group.

format

a logical value indicating whether the output should be formatted.

digits

a numerical value defining of digits to present the results.

file

a character indicating the name of output file in csv format to be saved.

...

additional input arguments that may be used when creating your own function.

Details

The functions std_km and std_km_group are standard functions that can be modified by the user in order to customize the barplots a prior. The plots also can be modified a posterior as a regular ggplot object. See std_km and std_km_group.

Value

a list of ggplot objects with each item named by the column names from var.

Examples

library(dplyr)
library(survival)
data(lung)

lung_nt <- lung |> mutate(sex = factor(sex, levels = 1:2,
                                    labels = c("Female", "Male")),
                       ph.ecog = as.factor(ph.ecog)) |>
                       select(sex, ph.ecog, time, status)
lung_nt |> nt_km(time = time, status = status,
                 labels = list(sex = "Sex", ph.ecog = "ECOG"))


dnzmarcio/ntimes documentation built on Feb. 5, 2025, 8:57 a.m.