Skip to contents

Generates and returns a ggplot object for Kaplan-Meier (KM) survival curves or time-dependent ROC curves.

Usage

figure_pro(type, data, file = NULL, time_unit = "days")

Arguments

type

String, specifies the type of plot. Options are "km" or "tdroc".

data

A list object containing model evaluation results. It must include:

  • sample_score: A data frame with "time", "outcome" (0/1), and "score".

  • evaluation_metrics: Contains "KM_Cutoff" for "km" plots, and "AUROC_Years" (a numeric vector) for "tdroc" plots.

file

Optional. A string specifying the path to save the plot. If NULL (default), the plot object is returned.

time_unit

String, the unit of time ("days", "months", "years"). Defaults to "days".

Value

A ggplot or ggsurvplot object. If file is provided, the plot is also saved.

Examples

# \donttest{
# Example data for a prognostic model
set.seed(42)
external_eval_example_pro <- list(
  sample_score = data.frame(
    time = runif(200, 10, 1825), # time in days
    outcome = sample(c(0, 1), 200, replace = TRUE, prob = c(0.7, 0.3)),
    score = runif(200, 0, 1)
  ),
  evaluation_metrics = list(KM_Cutoff = 0.5, AUROC_Years = c(1, 3, 5))
)

# Generate a Kaplan-Meier plot object
# Note: ggsurvplot returns a list, the plot is in the 'plot' element
km_plot_list <- figure_pro(type = "km", data = external_eval_example_pro, time_unit = "days")
# To display: print(km_plot_list)

# Generate a Time-Dependent ROC curve plot object
tdroc_plot <- figure_pro(type = "tdroc", data = external_eval_example_pro, time_unit = "days")
# To display: print(tdroc_plot)
# }