survminer icon indicating copy to clipboard operation
survminer copied to clipboard

Plotting the output of flexsurvreg

Open kassambara opened this issue 7 years ago • 13 comments

(e-mail from a user)

Is it possible that we could plot the output of flexsurvreg using survminer just as we do plot.flexsurvreg.

kassambara avatar Apr 03 '17 07:04 kassambara

I'd love to have this too! Are you open to contributions?

Thanks, Peter.

lemna avatar Sep 04 '17 12:09 lemna

Hi @lemna

Yes, contributions are welcome!! Thanks

kassambara avatar Sep 04 '17 16:09 kassambara

@lemna are you working on this? If no, I'll work on it

kassambara avatar Oct 09 '17 18:10 kassambara

I am - will do a PR in the coming days.

lemna avatar Oct 10 '17 14:10 lemna

As I also needed this feature now, I've started to implemented it this morning. I'll push a commit in a second so that other can modify it.

kassambara avatar Oct 10 '17 15:10 kassambara

First version of ggflexsurvplot() available now:

if(!require("flexsurv")) install.packages("flexsurv")
devtools::install_github("kassambara/survminer")

library(survminer)
require("flexsurv")
fit <- flexsurvreg(Surv(rectime, censrec) ~ group,
                   dist = "gengamma", data = bc)
ggflexsurvplot(fit)

rplot

kassambara avatar Oct 10 '17 15:10 kassambara

Thanks for adding the flexsurvreg functionality. When using ggflexsurvplot with a weibull a get the following error:

Error in .get_data(fit, data = data, complain = FALSE) : The data argument should be provided either to ggsurvfit or survfit.

klausmiller avatar Apr 26 '18 07:04 klausmiller

Is there any way that we can plot all the distributions together along with the KM?

Abhiroop-2924 avatar Sep 20 '18 18:09 Abhiroop-2924

Lest no good deed go unpunished, it would be great to have the full set of ggsurvplot variants available, especially ggsurvplot_facet for models with multiple covariates.

I'm guessing the general solution would be a utility to translate the output objects from flexsurvreg to the survfit class. Not something I can do.

martinamorris avatar Dec 11 '20 02:12 martinamorris

First version of ggflexsurvplot() available now:

if(!require("flexsurv")) install.packages("flexsurv")
devtools::install_github("kassambara/survminer")

library(survminer)
require("flexsurv")
fit <- flexsurvreg(Surv(rectime, censrec) ~ group,
                   dist = "gengamma", data = bc)
ggflexsurvplot(fit)

rplot

This plot no longer works, even with groups as factors and add.all = FALSE. The resulting figure has strata = all added to the plot, and the KM curve is combined to one pooled curve with risk.table also pooled. Can someone please help to plot output of a stratified flexsurv object superimposed over stratified KM curves?

Output looks as follows: https://rpkgs.datanovia.com/survminer/reference/ggflexsurvplot.html

jaclynbeca avatar Jun 04 '21 19:06 jaclynbeca

I'm having the same issue (all strata combined). I ended up building my own overlay ggplot from the KM and flexsurvreg outputs.

ApexHeel avatar Jun 08 '22 16:06 ApexHeel

is it possible to separate strata KM and fit to separate plot or facet? ex:3 plots or facets for above plot.

somkamalin avatar Jan 21 '23 19:01 somkamalin

First version of ggflexsurvplot() available now:

if(!require("flexsurv")) install.packages("flexsurv")
devtools::install_github("kassambara/survminer")

library(survminer)
require("flexsurv")
fit <- flexsurvreg(Surv(rectime, censrec) ~ group,
                   dist = "gengamma", data = bc)
ggflexsurvplot(fit)

rplot

I did plot for recurrent event analysis with start, stop time in flexsurvreg then by using ggflexsurvplot. In this case, is it first event KM plot overlaid with first event model curve? OR it accounts for all events regardless of subject(counting method-anderson-gill method). I assume later is correct by checking code. can you please confirm?

somkamalin avatar Jun 02 '23 03:06 somkamalin