I would like to have the axis crossing at 0,0 in ggsurvplot. There is a similar older question here ggsurvplot - axes crossing at 0,0. However, I am having errors with this method.
First error due to adding confidence intervals conf.int = T
:
Error in ggpubr::geom_exec(.geom_confint, data = d, ymin = "lower", ymax = "upper", : object '.geom_confint' not found
Second error occurs when adding median survival lines surv.median.line = "hv"
:
Error in .add_surv_median(p, fit, type = surv.median.line, fun = fun, : could not find function ".add_surv_median"
Is there another way to solve this?
ggsurvplot(fit, data = lung)
Thanks in forward
CodePudding user response:
If I understand you right then you could achieve your desired result by removing the default expansion via scale_x/y_continuous
like so:
library(survminer)
library(survival)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggsurvplot(fit, data = lung)
p$plot <- p$plot
scale_x_continuous(expand = c(0, 0, .05, 0))
scale_y_continuous(expand = c(0, 0, .05, 0))
p