1

I am trying to flip x and y for my survival analysis plot (using the survival/survminer package), but when I add coord_flip() to this line of code:

ggsurvplot(poop_fit, data = egg.data, pval = TRUE, conf.int = TRUE, coord_flip())

I get this error:

Error in .apply_surv_func(df, fun = fun) : Invalid 'fun' argument

Does anyone know if there is another way to flip the coordinates in survival analysis?

bibigeans
  • 115
  • 5

1 Answers1

2

You can access/manipulate the plot by accessing it using '$plot', e.g. ggsurvplot(fit, data = lung)$plot. For example:

require("survival")
require("survminer")

fit<- survfit(Surv(time, status) ~ sex, data = lung)

ggplot1 <- ggsurvplot(fit, data = lung)$plot
df1 <- data.frame(time=fit$time, nRisk=fit$n.risk, nRiskRel=fit$n.risk/max(fit$n.risk))  
ggplot1 + geom_point(aes(x=time, y=nRiskRel), data = df1, alpha=0.5, size=3)
ggplot1 + coord_flip()

Pre-flipped (no + coord_flip()):

pre-flipped.png

Post-flipped (with + coord_flip()):

post-flipped

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46