I'm trying to make a survival curve with the use of ggsurvplot. I've tried making a separate fit where the formula is invalid, putting the survfit formula directly into ggplot, and finally got a out a figure using a model as a fit, but even this comes out wrong.
I have three different doses in my dataset I want to compare, a control and 2 treatments. I also have different generations I wish to add, but for now I simply want to have a functioning code before putting in more complexity.
When trying to make a fit:
fit <- survfit(formula = (Surv(time=Age) ~ Dose),data=LongL1)
ggsurvplot(fit,data=LongL1)
Received error:
Error in formula.default(object, env = baseenv()) : invalid formula
Inserting model into fit:
ModLong1 <- coxph(Surv(time=Age) ~ Dose,data=LongL1)
fit <- survfit(ModLong1,data=LongL1)
ggsurvplot(fit,data=LongL1)
The curve created comes out as a combined graph rather than three separate. How do I fix this?1