kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
509 stars 164 forks source link

Centre Title Hack No Longer Works #585

Open DarioS opened 2 years ago

DarioS commented 2 years ago

The solution proposed in #463 creates a left-centred title these days.

library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(survival)
fit <- survfit(Surv(time, status) ~ 1, data = aml)
plot <- ggsurvplot(fit, data = aml, title = "Reproducible Example")
plot[["plot"]] + theme(title = element_text(hjust = 0.5))

Created on 2022-05-04 by the reprex package (v2.0.1)

image

Also, note that the default value of conf.int is FALSE, but confidence intervals are drawn regardless. The default was ignored.

rschauner commented 2 years ago

I'm not a maintainer, but I have somewhat of a solution.

plot <- ggsurvplot(fit, data = aml, title = "Reproducible Example", conf.int = FALSE)
plot[["plot"]] + theme(plot.title = element_text(hjust = 0.5))

It seems somewhere along the line, the title information is being set as plot.title instead of title.

As for your problem with conf.int being set to false but still returning a plot with confidence intervals. I found the problem where when calling ggsurvplot and you have no strata defined and did not explicitly set conf.int to either true or false, it is automatically set to true. I think that is a poor design decision as it is not clear that explicitly setting the value to the default value gets rid of this behavior.