1

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

ebay
  • 109
  • 1
  • 7

1 Answers1

2

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

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Yeah, that's it. Can I manipulate the survival plot by doing this as if it was a ggplot ? – ebay Sep 12 '22 at 22:58
  • 1
    Yep. You only have to take into account that a `ggsurvplot` object is basically a list where the `ggplot` object is stored as an element with name ´plot`. – stefan Sep 12 '22 at 23:03