Which curve is which in Survival Function plot?

Viewed 357

I am plotting survival functions with the survival package. Everything works fine, but how do I know which curve is which? And how can I add it to a legend?

  url <- "http://socserv.mcmaster.ca/jfox/Books/Companion/data/Rossi.txt"
  Rossi <- read.table(url, header=TRUE)[,c(1:10)]
  km <- survfit(Surv(week, arrest)~race, data=Rossi)
  plot(km, lty=c(1 ,2))
3 Answers

Thanks to the answer of Richard, I found a way to plot the right names to the right curves, with the base plot way that is used in plot.survfit:

legend_values <- names(km$strata)
plot(km)
legend(
  "topright",
  legend=legend_values,
  col=1:2,
  lty = c(1,1),
  horiz=FALSE,
  bty='n')

I prefer the ggplot way of plotting, but I like to retain the stepwise presentation in plot.survfit.

Related