Christopher W. Ryan
2024-Jun-17  19:53 UTC
[R] unable to get barchart of censored subjects from ggsurvplot() in survminer package, if there is no predcitor
Hello. Running R 4.2.3 on Windows 10. Using survimer package version
survminer_0.4.9 published 2021-03-09.
I'm encountering an error with ggsurvplot() in the survminer package.
Email to the author/maintainer about 2 weeks ago has not yet resulted in
a reply.
I seem unable to produce a n.censor.table for
an unconditional (no predictor) survival curve. See code below.
Any advice?
Thanks.
--Chris Ryan, MD, MS, MSPH
library(survival)
library(survminer)
data(lung)
fit <- survfit(Surv(time, status) ~ 1, data = lung)
ggsurvplot(
           fit,
           data = lung,
           xlab = "Time in days",
           ncensor.plot = TRUE
                  )
## produces error "Error:
! Problem while converting geom to grob.
? Error occurred in the 1st layer.
Caused by error:
! Unknown colour name: strata"
about "uknown colour name strata"
## but there are no strata
## omit ncensor.plot, and no error
ggsurvplot(
           fit,
           data = lung,
           xlab = "Time in days",
       #   ncensor.plot = TRUE
                  )
## restore ncensor.plot = TRUE, but use a predictor in the model,
## and no error.
fit.2 <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(
           fit.2,
           data = lung,
           xlab = "Time in days",
           ncensor.plot = TRUE
                  )
Ivan Krylov
2024-Jun-20  16:49 UTC
[R] unable to get barchart of censored subjects from ggsurvplot() in survminer package, if there is no predcitor
? Mon, 17 Jun 2024 15:53:16 -0400 "Christopher W. Ryan via R-help" <r-help at r-project.org> ?????:> Caused by error: > ! Unknown colour name: strata" > about "uknown colour name strata" > ## but there are no stratarlang::last_trace() demonstrates that the error happens because some code receives a string 'strata' and tries to decode it as a name of a colour: farver::decode_colour('strata') # Error: Unknown colour name: strata This appears to originate from the first layer of the ncensor.plot: p <- ggsurvplot( fit, data = lung, xlab = "Time in days", ncensor.plot = TRUE ) p$ncensor.plot$layers[[1]]$aes_params # $colour # [1] "strata" # # $fill # [1] "strata" This can be traced further but I'm not sure how to fix the bug without strata. Giving an explicit argument color = 'black' to ggsurvplot() results in a warning but at least doesn't raise an error while drawing the plot. -- Best regards, Ivan