Maze
Maze

Reputation: 1

Kaplan-Meier Survival curve with 3 Plots

I am very new to R studio, and I am currently learning how to do Kaplan-Meier survival curves.

Here are the columns that are needed and the information the columns contain:

Group: “normal”, “high” Response: “responder” “non-responder” Days: this is the time variable Outcome: “0”, “1” (0 = censored & 1 = event)

I’m trying to plot 3 plots on one survival curve (Kaplan-Meier curve). I want to plot Normal (regardless of responder status) vs High Responder vs High Non-responder). Is there a way to do this?

I tried making subsets of data (one including only those that are “normal” and then another containing only those that were “high”) so that I could plot the normal (1 plot)(regardless of responder status) and the other subset could be used to plot the high responder vs high nonrepsonder (2 plots) but then I got stuck on how to combine them.

Upvotes: 0

Views: 2188

Answers (1)

David L Thiessen
David L Thiessen

Reputation: 694

After you've created the first plot you can add the other lines over top of the first plot. Here's an example doing that with the built-in cancer dataset. I make the people aged 60 or older all in one group, but split the people under 60 into two groups based on their sex.

library(survival)
dat_60plus <- cancer[cancer$age >= 60,]
dat_under60 <- cancer[cancer$age < 60,]

mod_60plus <- survfit(Surv(time, status) ~ 1, data = dat_60plus)
mod_under60sex <- survfit(Surv(time, status) ~ sex, data = dat_under60)

plot(mod_60plus, conf.int = FALSE)
lines(mod_under60sex, conf.int = FALSE, col = c("blue", "red"))

Alternatively you could create a new variable which identifies which group each individual is in and make a single model based on that variable. I think this is conceptually a bit simpler, so long as creating the variable isn't too complicated.

dat_all <- cancer
dat_all$myvar <- factor(ifelse(cancer$age >= 60,
                               "60plus",
                               ifelse(cancer$sex == 1,
                                      "under60male",
                                      "under60female")))
mod_all <- survfit(Surv(time, status) ~ myvar, data = dat_all)
plot(mod_all, conf.int = FALSE, col = c("black", "red", "blue"))

Created on 2023-01-25 with reprex v2.0.2

A potential downside of the first method is that if one of the groups has much longer survival time than the others, then you might have to do more adjusting of the graphical settings to make the plot look good. The second method should have more automatic checks for that.

Upvotes: 1

Related Questions