pharmaverse / ggsurvfit

http://www.danieldsjoberg.com/ggsurvfit/
Other
72 stars 20 forks source link

Bug Report: `add_quantile()` places line segments when median survival not met #53

Closed ddsjoberg closed 2 years ago

ddsjoberg commented 2 years ago

When the survival quantile is not met, add_quantile() is placing the line segment at the last followup instead of omitting it

library(ggsurvfit)

survfit2(Surv(time, status) ~ surg, data = df_colon) |> 
  tidy_survfit() %>%
  dplyr::filter(strata == "Short") |> 
  dplyr::slice_tail(n = 1) %>%
  dplyr::select(time, strata, estimate)
#> # A tibble: 1 × 3
#>    time strata estimate
#>   <dbl> <fct>     <dbl>
#> 1  9.11 Short     0.505

survfit2(Surv(time, status) ~ surg, data = df_colon) |>
  # build Kaplan-Meier plot ----------------------------------------------------
  ggsurvfit(size = 1) +
  add_confidence_interval() +
  add_risktable() +
  add_quantile(color = "gray50", size = 0.7, y_value = 0.2)

Created on 2022-08-14 by the reprex package (v2.0.1)