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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top