title: How to vary color and line type in ggsurvplot?
body: <p>I would like to produce the Kaplan-Meier plot from the <code>lung</code> dataset in the <code>survival</code> package, stratified on sex and ECOG score. I would like the curves to have the following styles:</p>
  <pre><code>Men, ph.ecog = 0: solid, red
  Men, ph.ecog = 1: solid, blue
  Men, ph.ecog = 2: solid, green
  Women, ph.ecog = 0: dashed, red
  Women, ph.ecog = 1: dashed, blue
  Women, ph.ecog = 2: dashed, green
  </code></pre>
  <p>I would like to display the risk table below the plot. It would be especially nice to display the line style (color and type) in the risk table legend in place of the long legend labels.</p>
  <p>I tried this code based on the answer from <a href="https://stackoverflow.com/questions/51387396/different-color-type-and-line-type-for-multiple-groups-in-survival-curve">different color type and line type for multiple groups in survival curve</a>:</p>
  <pre><code># drop the PH.ECOG level with only 1 observation
  lung$ph.ecog[lung$ph.ecog == 3] &lt;- NA
  
  fit &lt;- survfit(Surv(time, status) ~ sex + ph.ecog, data = lung)
  
  p &lt;- ggsurvplot(fit, 
             data= lung, 
             title=&quot;Survival Probability by Sex and ECOG&quot;, 
             xlab = &quot;Days&quot;, 
             ylab = &quot;Survival Probability&quot;,
             conf.int = FALSE, 
             pval=TRUE, 
             pval.coord = c(0,0.25),
             risk.table = TRUE,
             risk.table.pos=&quot;out&quot;,
             risk.table.col=&quot;black&quot;,
             risk.table.y.text.col=TRUE,
             risk.table.height = 0.2,
             tables.theme = theme_cleantable() + theme(aspect.ratio = 0.2),
             tables.y.text = FALSE,
             break.time.by=180,
             legend.labs = c(
                   &quot;Male, asymptomatic&quot;,
                   &quot;Male, symptomatic but completely ambulatory&quot;,
                   &quot;Male, in bed &lt;50% of the day&quot;,
                   &quot;Female, asymptomatic&quot;, 
                   &quot;Female, symptomatic but completely ambulatory&quot;, 
                   &quot;Female, in bed &lt;50% of the day&quot;
                    ),
             censor=TRUE,
             legend.title=&quot;&quot;,
             linetype = &quot;strata&quot;,
             ggtheme = theme_survminer() + theme(plot.title = element_text(hjust = 0.5, face = &quot;bold&quot;), aspect.ratio = 1)
  )
  
  cols &lt;-  rep(c(&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;), 2)
  names(cols) &lt;- paste(&quot;Sex&quot;, rep(c(&quot;Male&quot;, &quot;Female&quot;), each = 3), &quot;ECOG&quot;, 0:2)
  
  lines &lt;-  rep(c(&quot;solid&quot;, &quot;dashed&quot;), each = 3)
  names(lines) &lt;- paste(&quot;Sex&quot;, rep(c(&quot;Male&quot;, &quot;Female&quot;), each = 3), &quot;ECOG&quot;, 0:2)
        
  p$plot &lt;- p$plot +
    scale_linetype_manual(values = lines) +
    scale_color_manual(values = cols)
  
  p$plot / p$table + patchwork::plot_layout(ncol = 1, heights = c(3, 1)) +
    theme(axis.text.y = element_text(color = rev(cols)))
  
  print(p)
  
  </code></pre>
  <p>The resulting plot area is empty and a warning message is returned:</p>
  <pre><code>Removed 225 row(s) containing missing values (geom_path).
  Removed 63 rows containing missing values (geom_point).
  Removed 225 row(s) containing missing values (geom_path).
  Removed 63 rows containing missing values (geom_point).
  </code></pre>
  <p>Thank you in advance for your help.</p>