Jasmin
Jasmin

Reputation: 1

Error in `ggsurvfit()`: ! `ggsurvfit()` cannot be used to plot objects of class <survfit2/survfitms/survfit>

Can someone explain to me why this error message keeps coming up? My previous time-to-event analyses have all worked perfectly with the same commands. Tank you.

My skript contains the following:

dfit <- survfit2(Surv(time, status) ~ intervention, data = Drugs_discon)

summary(dfit)

ggsurvfit(dfit)

Error in ggsurvfit(): ! ggsurvfit() cannot be used to plot objects of class <survfit2/survfitms/survfit>. ℹ Use ggcuminc() for competing risks cumulative incidence plotting. Run rlang::last_trace() to see where the error occurred.

Upvotes: 0

Views: 332

Answers (1)

Loris
Loris

Reputation: 81

I can't confirm without a reproducible example but I'm fairly sure the problem is that status is considered a factor in your dataframe. You can put

dfit <- survfit2(Surv(time, as.numeric(status)) ~ intervention, data = Drugs_discon)
summary(dfit)
ggsurvfit(dfit)

This should produce the required plot

Upvotes: 1

Related Questions