How to merge the legend of linetype and palette in ggsurvplot with strata

Hi! Is there a way to edit the linetyep AND color of the lines in ggsuvplot?

I have the following code so far:

g = ggsurvplot(fit, 
               size = 0.8,
               legend = c(0.9, 0.7),
               # linetype = c(1,2),
               linetype = "strata", 
               palette = c("#fa5cf2", "#fa5cf2", "#ffa600", "#84d94e","#f25c78","#f25c78", "#b64cdf","#b64cdf"),
               legend.title = element_blank(),
               legend.labs = c("A","B",
                               "C", "D",
                               "G", "H"),
               xlim = c(0,11),
               font.legend = c(13, "plain", "black"),
               font.x = c(15, 'plain', 'black'),
               font.y = c(15, 'plain', 'black'),
               font.tickslab = c(11, 'plain', 'black'),
               surv.scale = 'percent'

I get the following graph:

Basically, there are two legends there: 1 for the linestyle and 2 for the color.
I want to modify the linestyle for A so that is has the dashed line, while the rest (B to H) are purely solid line. On top of that, I want to retain the color of the line as indicated by the array of colors in the palette.
How to go about this? Thank you!

example of modifying the linetype

fit<- survfit(Surv(time, status) ~ sex, data = lung)

# Basic survival curves
ggsurvplot(fit, data = lung,linetype = "strata")$plot

#your own choice of linetype
ggsurvplot(fit, data = lung,linetype = "strata")$plot +
  scale_linetype_manual(values = c("sex=1"="dotted",
                                   "sex=2"="dashed") )

Hi. Thanks for the response.
How do you change the color of the sex=1 and sex=2 on top of the linetype?

Try scale_color_manual

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.