Closed traversc closed 4 years ago
It appears ggsurv also provides its own +
method and isn't really a "standard" extension, so that is unfortunately a no...
If ggsurv provides some way of turning the plot into a gtable or grob (e.g. works with ggplotGrob()
) you could convert it to that and add it, but other than that I don't know. Maybe reach out to the ggsurv developers and see if they are interested in making it behave more like a standard ggplot2 extension...
> class(g1$plot)
[1] "gg" "ggplot"
> class(g1$table)
[1] "gg" "ggplot"
surv2patch <- function(p) (p$plot / p$table) + plot_layout(heights = c(3,1))
surv2patch(g1) | surv2patch(g2)
The survminer
package seems to create a bespoke object that is not fully ggplot2 compatible. But there's a newer package for plotting survival curves called ggsurvfit
, which creates ggplot2 compatible objects, so you can add layers and adjust themes.
ggsurvfit creates a plot object of class "ggsurvfit" "gg" "ggplot"
I found this doesn't work with patchwork, but if you manually reset the class prior to composing your plot in patchwork...
class(plot_1) <- c("gg", "ggplot")
class(plot_2) <- c("gg", "ggplot")
class(plot_3) <- c("gg", "ggplot")
... that works.
ggsurv
plots from thesurvminer
package has become a standard for survival analyses.Would it be possible to get
patchwork
working with it out of the box?A reproducible example: