surv_group: Generate Kaplan-Meier Survival Plots for Categorical Groups

View source: R/surv_group.R

surv_groupR Documentation

Generate Kaplan-Meier Survival Plots for Categorical Groups

Description

Creates Kaplan-Meier survival plots for data grouped by a categorical variable. Handles both binary and multi-level categorical groups with customizable plot aesthetics.

Usage

surv_group(
  input_pdata,
  target_group,
  ID = "ID",
  levels = c("High", "Low"),
  reference_group = NULL,
  project = NULL,
  time = "time",
  status = "status",
  time_type = "month",
  break_month = "auto",
  cols = NULL,
  palette = "jama",
  mini_sig = "score",
  save_path = NULL,
  fig.type = "pdf",
  index = 1,
  width = 6,
  height = 6.5,
  font.size.table = 3
)

Arguments

input_pdata

Data frame containing survival data and grouping variables.

target_group

Name of column containing the grouping variable.

ID

Name of column with unique identifiers. Default is "ID".

levels

Names for levels of target_group (for binary groups). Default is c("High", "Low").

reference_group

Reference level for binary comparison. Default is NULL.

project

Optional title for plot. Default is NULL.

time

Name of column with follow-up times. Default is "time".

status

Name of column with event indicators. Default is "status".

time_type

Units: "month" or "day". Default is "month".

break_month

X-axis break interval. If "auto", calculated automatically. Default is "auto".

cols

Color vector for plot lines. Default is NULL.

palette

Color palette name. Default is "jama".

mini_sig

Prefix label for variables. Default is "score".

save_path

Directory for saving plot. Default is NULL.

fig.type

File format: "pdf" or "png". Default is "pdf".

index

Identifier for file naming. Default is 1.

width

Plot width. Default is 6.

height

Plot height. Default is 6.5.

font.size.table

Font size for risk table. Default is 3.

Value

Kaplan-Meier plot object.

Author(s)

Dongqiang Zeng

Examples

# Simulate data
set.seed(123)
sim_pdata <- data.frame(
  ID = paste0("Sample", 1:100),
  Lauren = sample(c("Intestinal", "Diffuse"), 100, replace = TRUE),
  time = runif(100, 1, 60),
  OS_status = sample(0:1, 100, replace = TRUE)
)
# Run survival analysis (survival and survminer are imported packages)
result <- surv_group(
  input_pdata = sim_pdata,
  target_group = "Lauren",
  time = "time",
  status = "OS_status",
  save_path = NULL
)
if (!is.null(result)) print(result)

IOBR documentation built on May 30, 2026, 5:07 p.m.