Home > database >  Survminer - include subset of variables in plot
Survminer - include subset of variables in plot

Time:08-02

Let's say I want to plot the survival curves using a model of the lung data, that controls for sex and a median split of the age variable (I could also control linearly for age and that would make my problem even worse).

I would like to make a plot of this model only showing the stratification between the levels of the sex factor. If I do what seems to be the standard, however, I get 4 instead of two survival curves.

library(survival)
library(survminor)
reg_lung <- lung %>% mutate(age_cat = ifelse(age > 63, "old", "young"))
lung_fit <- survfit(Surv(time, status) ~ age_cat   sex, data = reg_lung)
ggsurvplot(lung_fit, data = reg_lung)

enter image description here

  • Related