Weird behavior of ggsurvplot about confidence interval

Viewed 1106

I am building the survival curves for the following dataset:

cont.Time <- c(5.1,5.4,5.7,5.9,5.9,6,6.1,6.3,6.8,7,7.1,7.4,7.4,7.4,7.4,7.6,8.8,8.8,8.9,9.1,9.9,9.9,10.1,10.4,10.5,11.1,11.3,11.4,11.5,11.7,13.5,13.5,14.1,14.2,15.2,15.9,16.1,16.3,16.5,16.6,16.6,16.6,16.6,16.7,16.8,16.8,16.9,16.9,17,17.1,17.2,17.3,17.5,17.5,17.8,17.9,17.9,18.4,18.7,19.4,19.6,19.7,19.9,19.9,19.9,19.9,20.1,20.3,20.5,20.6,20.8,20.9,21.1,21.2,21.2,21.3,21.7,21.9,22.1,22.4,22.9,23,23.1,23.3,23.8,24.1,24.6,24.8,24.9,24.9,25,25.1,25.1,25.2,25.3,25.4,25.4,25.6,26.6,26.7,27.1,27.2,27.4,27.4,27.5,27.6,27.6,27.8,28,28.2,28.3,28.5,28.8,28.8,28.9,28.9,29,29.1,29.2,29.4,29.6,29.9,30.1,30.5,30.6,30.6,30.6,30.6,30.6,30.7,31,31.1,31.3,31.6,31.8,32.9,33.1)
cont.Evt <- c(rep(1,54), rep(0,83))
cont.Strata <- unlist(strsplit("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYXYYYXYXYYYXYYXYXYYYXXYYYXYYXXXYYYXYYYYYXXXYYYXYXYYYYYXYYYYYYYYYYYYXYYYYYXYYYYYXYYXYYYYYXYYYYYYXYXXYYXXY",split=''))

df1 <- structure(list(Time=cont.Time,Evt=cont.Evt,Strata=cont.Strata),class="data.frame",row.names=c(NA,-137L))

(sorry for the ugly presentation, I could not reduce it to anything smaller)

print(df1)
#     Time Evt Strata
# 1    5.1   1      X
# 2    5.4   1      X
# 3    5.7   1      X
# ...
# 135 31.8   0      X
# 136 32.9   0      X
# 137 33.1   0      Y

When I am calling ggsurvplot() with conf.int=TRUE, it builds the plot without confidence interval:

p0 <- ggsurvplot(survfit(Surv(Time,   Evt) ~ Strata, data = df1[1:137,]), conf.int=TRUE)

plot0

If I do the same but without the last row in the table, it starts showing confidence interval for one strata:

p1 <- ggsurvplot(survfit(Surv(Time,   Evt) ~ Strata, data = df1[1:136,]), conf.int=T)

plot1

And if I remove 2 or more last rows, it shows confidence intervals for both, as desired:

p2 <- ggsurvplot(survfit(Surv(Time,   Evt) ~ Strata, data = df1[1:135,]), conf.int=T)

plot2

What's going on there?

UPD. Found this was reported as an issue at survminer repo.

Tried to debug it but unsuccessfully. I only found that it's sufficient to replace just one component of the plot:

data.Bad <- p0$plot$layers[[3]]$data
data.Good <- data.Bad[order(data.Bad$time),][1:115,]
p0$plot$layers[[3]]$data <- data.Good
2 Answers

I had the same issue when using xlim() to plot only a part of the data, the confidence interval disappeared. I solved it by using another confidence interval style::

p0 <- ggsurvplot(survfit(Surv(Time,   Evt) ~ Strata, data = df1[1:137,]), conf.int=TRUE, conf.int.style = "step")

I hope it will work for you !

I don't know the details of why this works but in the github issue you mentioned in your question there is an answer with an ad hoc solution.

shilsenbeck:
I have the same problem. the problem disappeared when I added an
explicit xlim= that extends the x-axis enough to capture the max value.

So for the example in this thread the solution would be:

p0 <- ggsurvplot(survfit(Surv(Time, Evt) ~ Strata, data = df1[1:137,]),
                 conf.int = TRUE,
                 xlim = c(0, max(df1$Time)))
Related