1

I have a dataframe like this

df = data.frame(time=c(1,2,3,4,1), event=c(1,1,0,0,1))

I want to create a survival curve

library(survival)
km <- survfit(Surv(time,event) ~ 1, data = df)

library("survminer")

ggsurvplot(km,  color = "#2E9FDF",
                    data =df,
           ncensor.plot = TRUE)

That's ok, but get warning

Warning message:
Now, to change color palette, use the argument palette= '#2E9FDF' instead of color = '#2E9FDF' 

I change

ggsurvplot(km,  palette = "#2E9FDF",
                    data =df,
           ncensor.plot = TRUE)

And we have error

Error in grDevices::col2rgb(colour, TRUE) : invalid color name "strata"

The problem is in ncensor.plot. When we remove it no error

ggsurvplot(km,  palette = "#2E9FDF",
                        data =df)

how to fix Error in grDevices::col2rgb(colour, TRUE)

Edward
  • 4,443
  • 16
  • 46
  • 81
  • 1
    Looks like a bug in the code. It doesn't work when you have only one strata (you have a constant `~1`). You might consider filing a [github issue](https://github.com/kassambara/survminer/issues) with the package author (or just ignoring the warning you get when you use `color=`) – MrFlick Jun 14 '19 at 14:58
  • 1
    Actually never mind, there already seems to be an issue for exactly this case: https://github.com/kassambara/survminer/issues/298 – MrFlick Jun 14 '19 at 14:59

0 Answers0