3

I am using survival analysis to show the proportion of individuals/duration to reach a developmental milestone, and I would like to flip the y-axis ticks so it has 0 at the top and 1.00 at the bottom. I tried using scale_y_reverse, but this flipped the results too. I just want the axis ticks to go from 0-1, while maintaining the visuals of the first graph. Thanks for your help!!

ggsurvplot(spin_fit, data = spin.data, pval = TRUE, conf.int =  TRUE) 
ggplot2 <- ggsurvplot(spin_fit, data = spin.data, pval = TRUE)$plot
df1 <- data.frame(time=spin_fit$time, nRisk=spin_fit$n.risk, nRiskRel=spin_fit$n.risk/max(spin_fit$n.risk))  
ggplot2 + geom_point(aes(x=time, y=nRiskRel), data = df1, alpha=0.5, size=3)
ggplot2 + ylab("Proportion of Larvae Spinning Cocoon") ]

survival plot not flipped

Here's what happened when I added to the last line: ggplot2 + ylab("Proportion of Larvae Spinning Cocoon") + scale_y_reverse()

survival plot flipped

bibigeans
  • 115
  • 5

2 Answers2

3

You could try to use scale_y_continuous to set your own breaks and labels:

break_values <- c(0, 0.25, 0.5, 0.75, 1)
ggplot2 + scale_y_continuous(breaks = break_values,
                             labels = as.character(rev(break_values)))
rps1227
  • 472
  • 2
  • 5
2

ggsurvplot also natively supports this without manually messing with the scales through the fun argument.

From the help section:

fun: an arbitrary function defining a transformation of the survival curve. Often used transformations can be specified with a character argument: "event" plots cumulative events (f(y) = 1-y), "cumhaz" plots the cumulative hazard function (f(y) = -log(y)), and "pct" for survival probability in percentage.

So all you need to do is:

ggplot2 <- ggsurvplot(spin_fit, data = spin.data, pval = TRUE, fun = "event")$plot
Erik A
  • 31,639
  • 12
  • 42
  • 67