Log-minus-log-plots using `ggsurvfit::ggsurvfit()`

46 views Asked by At

Is it possible to produce a log-minus-log plot using ggsurvfit::ggsurvfit()?

Here's an example of what I want to produce:

library(ggsurvfit)
temp <- survfit2(Surv(time, status) ~ adhere, data = df_colon)
plot(temp, fun = \(x) log(-log(x)))

but instead of using plot() I want to use ggsurvfit::ggsurvfit(). I tried the following

temp$surv <- log(-log(temp$surv))
ggsurvfit(temp)

but it behaves weirdly in the beginning of the plot because the survival curve is 1 at time 0.

1

There are 1 answers

1
SamR On BEST ANSWER

The issue is that ggsurvfit() assumes that y=1 at time zero. This makes sense for a survival curve - you can't model the survival of people who are already dead - but not if you transform the y-axis.

To resolve this, as ggsurvit() produces a ggplot object, you can just set the axis limits to only include values which are actually there, removing the row containing this assumption. I would change the y-axis label as well.

ggsurvfit(temp) +
    scale_y_continuous(
        limits = (c(min(temp$surv), max(temp$surv)))
    ) +
    labs(
        y = "log(-log(surival probability))"
    )

enter image description here