4

When I plot the survfit plot of data with two different censoring events, the overall plot (s0) doesnt start at time = 0, pstate = 100%, but jumps to 100% when the first cencoring event occurs.

Jumping survival fit

Here you can see in an example, where the jump occurs at time 1, that is the first cencoring event.

library(survival)
library(ggfortify)
library(tidyverse)
set.seed(1337)

dummy_data = tibble(time = sample.int(100, 100, replace = TRUE),
                    event = sample.int(3, 100, replace = TRUE))%>%
  mutate(event = factor(event))

kaplanMeier <- survfit(Surv(time, event) ~ 1, data=dummy_data)
autoplot(kaplanMeier, facets = TRUE)
LittleLynx
  • 1,163
  • 2
  • 12
  • Looks like a bug in `ggfortify:::fortify.survfit`. The web page for the package is here: https://github.com/sinhrks/ggfortify; maybe someone there can suggest a way to fix it. – user2554330 Mar 30 '22 at 16:37

1 Answers1

2

This does seem to be a bug in ggfortify. As a temporary fix, you can set the survival percentage at t = 0 to 100% by doing:

p <- autoplot(kaplanMeier, facets = TRUE)

p$layers[[1]]$data[1, c(5, 7, 8)] <- 1
p

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thanks! Since in my original code, I used different strata, I adapted your workaround to this ` p$layers[[1]]$data$pstate[p$layers[[1]]$data$time == 0 & p$layers[[1]]$data$event == "(s0)"] = 1 p$layers[[1]]$data$lower[p$layers[[1]]$data$time == 0 & p$layers[[1]]$data$event == "(s0)"] = 1 p$layers[[1]]$data$upper[p$layers[[1]]$data$time == 0 & p$layers[[1]]$data$event == "(s0)"] = 1` It's not as short as your solution, though. – LittleLynx Mar 31 '22 at 07:42