0
votes

I am following the lung example from survminer package in 3.5.1. The initial code is below:

library("survminer")
require("survival")
fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data = lung)

This plots the survival by sex, all fine. It then occurred to me that I want to just graph sex=1 or sex=2 only. How do I only plot a subset of the data from fit?

1
...data = subset(lung, sex==1)Parfait
That worked. Thank you, Parfait.PCP

1 Answers

0
votes

Parfait's comment gives the answer but in general:

# to get all the subtypes
ggsurvplot(survfit(Surv(time, status) ~ sex, data = lung)
#to select one subtype
ggsurvplot(survfit(Surv(time, status) ~ sex, data = subset(lung, sex==1))
#to select multiple subtypes
ggsurvplot(survfit(Surv(time, status) ~ sex, data = subset(lung, sex %in% c(1,2)))