Home > Software engineering >  Removing the name of the column in the final graph when creating a Kaplan Meier curve
Removing the name of the column in the final graph when creating a Kaplan Meier curve

Time:01-20

In the image below you can see how the lines are labeled as "Scenario = actual", "Scenario=Best", & "Scenario = Worst". I can not for the life of me find away to make it so that it shows you how to return it as only "Actual", "Best" and "Worst" without including the name of the column = "Scenario".

enter image description here

Does anyone know which command would allow me to edit the graph this way?

Graph was found on: https://towardsdatascience.com/kaplan-meier-curves-c5768e349479 and accuratly visualises my problem.

I have tried using different labs and lab functions as well as remove the name of the variable.

CodePudding user response:

You can change the labels of the legend by modifying the legend.title parameter inside the ggsurvplot() function. Instead of passing an empty string " " you can pass a vector of labels that corresponds to the levels of the Scenario variable in the same order.

Code used as example on the website:

surv_object <- Surv(time = toy_dataset$Followup , event = toy_dataset$Eventtype)
fit1 <- survfit(surv_object ~ Scenario, data = toy_dataset)

j <- ggsurvplot(fit1, data = toy_dataset, xlim = c(0,11), conf.int = FALSE,  risk.table = "nrisk_cumcensor", legend.title = " ", tables.theme = theme_cleantable(), break.time.by = 2,  censor.shape = c("|"), censor.size = 6)

Here is an example of how you can change the labels of the legend:

j <- ggsurvplot(fit1, data = toy_dataset, xlim = c(0,11), conf.int = FALSE,  risk.table = "nrisk_cumcensor", legend.title = c("Actual", "Best", "Worst"), tables.theme = theme_cleantable(), break.time.by = 2,  censor.shape = c("|"), censor.size = 6)

CodePudding user response:

You can use the legend.lab option in ggsurvplot()

Example:

ggsurvplot(fit, data = df, risk.table = TRUE, legend.lab=c("Actual", "Best", "Worst"))
  • Related