Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the color of censor points on a ggsurvplot?

Censor points are very difficult to distinguish from the survival curve they're placed along when the colors match, which they do by default. I'd like to change the color of censor points on my plot, or maybe even give them a nice outline, so they can be easily distinguished from the survival curve.

I wrote the code below hoping to change the censor color to black, but the censor points on the plot it rendered are still the pesky curve-matching default colors.

library(survival)
library(survminer)

# Create a survfit using lung data
fit <- survfit(Surv(time, status) ~ sex, data = lung)

# Render plot with customized censor point color
ggsurvplot(
  fit,
  data = lung,
  censor.col = 1)
like image 649
Garrett Foster Avatar asked Oct 15 '25 16:10

Garrett Foster


1 Answers

While ggsurvplot understands censor.shape and censor.size the docs does not mention a censor.col(or) parameter.

But one option would be to manipulate the plot object directly, i.e. in your case we can set a "black" point color like so, where the third layer is the geom_point which adds the censor points:

library(survival)
library(survminer)

p <- ggsurvplot(
  fit,
  data = lung
)

p$plot$layers[[3]]$aes_params$colour <- "black"

p

like image 199
stefan Avatar answered Oct 18 '25 08:10

stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!