Pregunta

I am writing a script that will generate plots of plot(survfit(Surv(time, event)~factor)).

The different survival curves will have a different color. How is the order of the color defined? is it levels(factor)? unique(factor)?

My point is that I would like to automatically script the legend labels and text. Can I safely I use levels(factor) as legend text?

I am sure this is documented somewhere but the help entry of ?plot.survfit is not very helpful?

¿Fue útil?

Solución

Yes, the order of the color depends on levels(factor), and yes, you can use levels(factor) for your legend text.

This applies everytime you are dealing with a factor. There is also a number of functions for you to manipulate the levels of your factor if you need so, e.g. check ?relevel.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top