'Can I change the color of the surv.median.line in my Kaplan Meier plot using R ggsurvplot?

I use the script below to plot a Kaplan-Meier curve.

I think that the median survival line is a great tool. However, the median survival line is drawn as a dashed black line, which is graphically overwhelming. Can I change the color or the opacity of the survival line to decrease the graphic output from the surv.median.line function?

If not, can I manually add a vertical/horizontal median survival line in which I can change the color or the opacity?

j <- ggsurvplot(
  fit,                     
  data = p, 
  #fun="cumhaz",
  risk.table = "abs_pct", #risk.table.col="strata",
  pval = TRUE,      
  pval.coord = c(0, 0.25),
  conf.int = T,         
  #legend.labs=c("0-4%", "5-9%", "\u226510%"),
  cumevents.title = "Cumulative number of recurrences",
  size=c(0.8,0.8,0.8,0.8),                    
  xlim = c(0,10),
  alpha=0.8,
  break.x.by = 1,    
  xlab="Time in years",
  ylab="Probability of progression-free survival",
  ggtheme = theme_gray(),             
  risk.table.y.text.col = T,
  risk.table.y.text = TRUE, 
  surv.median.line = "hv",
  ylim=c(0,1),
  cumevents=TRUE,
  #palette=c("#222a37","darkred"),
  surv.scale="percent")

j 

I have tried to add the following, but I get this warning: Error in max(surv_median) : invalid 'type' (closure) of argument

surv_median <- as.vector(summary(fit)$table[, "median"])
df <- data.frame(x1 = surv_median, x2 = surv_median,
                 y1 = rep(0, length(surv_median)), y2 = rep(0.5, length(surv_median)))

j$plot <- j$plot + 
  geom_segment(aes(x = 0, y = 0.5, xend = max(surv_median), yend = 0.5),
               linetype = "dashed", size = 0.5)+ # horizontal segment
  geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = df,
               linetype = "dashed", size = 0.5) # vertical segments

print(j)


Solution 1:[1]

I made edits to the source shown by Roman Luštrik, which is found on GitHub in the survminer package's R folder and is titled "ggsurvplot_core.R".

I made a fork in GitHub that has a solid line instead but you can also make a fork that has color and alpha changes. Let me know if you are still trying to this even though it's been three years!

My fork with a solid line instead of dashed https://github.com/brandonerose/survminer.git

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1