I have done multiple survival models using kaplan-Meir approach, each survival model was built by extracting sub set of data to different R Data table based on group column showed in the data table. I can plot each survival curve separate but I want to plot all these different models in one plot. what is the best way to do that.
userid lifespan_days event group
2 4657 1 A
4 4658 1 A
16 1106 1 A
50 458 1 A
51 4393 1 A
57 305 1 A
It would be great to do this in ggplot, By search I found following ggplot2
- plot multiple models on the same plot but I have problem of doing such scenario due to the nature of my data. For example userid
is from multiple websites so userid=2
can exist under another group.
Lets say using above data.table I have created following:
a_time <- dt$lifespan_days
a_event <- dt$event
survival_model_a <- survfit(Surv(a_time, a_event) ~ 1)
plot(survival_model_a)
this will only plot one similary in the same plot I want to plot the model that I built for group b data which is in a different data.table / data.frame