Closed ddsjoberg closed 11 months ago
If you try to use the operators with 3 plots (with any operators) it throws an error.
p1 <- survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() +
add_risktable()
p2 <- survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() +
add_risktable()
p3 <- survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() +
add_risktable()
p1 | p2 | p3
Error in p1 | p2 | p3 : operations are possible only for numeric, logical or complex types In addition: Warning message: Incompatible methods ("|.ggplot", "|.ggsurvfit") for "|"
Also this doesn't work: (p1 | p2) / p3
The horizontal stack makes numbers in risk tables overlap.
p1 <- survfit2(Surv(time, status) ~ sex, data = df_lung) %>% ggsurvfit() + add_risktable()
p2 <- survfit2(Surv(time, status) ~ sex, data = df_lung) %>% ggsurvfit() + add_risktable()
p1/p2
Thanks for taking a look @michaelcurry1123 !
Regarding the first point: The issue is that after p1 | p2
is run, the result is no longer a ggsurvfit object (it's a regular patched together plot at that point. So when that result is then dispatched to . | p3
, we're no longer using the |.ggsurvfit
method and it's being dispatched via the patchwork method and it doesn't know how to handle the ggsurvfit plot.
Potential solutions:
I think for now, we'll need to opt for option one...I don't like the idea of exporting a conflicting method with patchwork AND I think it will be tricky to export this method while also trying to utilize the patchwork method in the background: there will be conflict.
Regarding the second point: That is just the default spacing. If you make the figure taller, the plots and risk tables will display appropriately
Ok that makes sense and if someone wants that customization you can do it like so:
library(gridExtra)
grid.arrange(p1,p2,p3,
layout_matrix =
matrix(
c(1,1,1,2,2,2,
1,1,1,2,2,2,
1,1,1,2,2,2,
1,1,1,2,2,2,
3,3,3,3,3,3,
3,3,3,3,3,3),
byrow = TRUE, ncol = 6)
)
Let's hold off on this until the next release for this. I would hope to get p | p | p
working properly if at all possible.
|.ggplot
method that could build and wrap the second argument as needed, then pass that object to the patchwork implementation of |.ggplot
?|.ggplot
methods. If we did more reading perhaps we could implement our own |.ggplot
methods, but pass those on to patchwork::wrap_plots()
instead of taking advantage of the patchwork arithmetic operators. I am not sure if this would interact with the other functions that work with the operators exported from patchwork.Oy!
complex issue! happy to help think through this with you for next release.
closing in favor of S7
What changes are proposed in this pull request?
|
,-
, and\
.Caveats:
+
operator.*
and&
because I am not really sure what they are for!wrap_elements()
. But that is pretty confusing to most users I would imagine.If there is an GitHub issue associated with this pull request, please provide link. closes #96
Reviewer Checklist (if item does not apply, mark is as complete)
renv::install()
_pkgdown.yml
pkgdown::build_site()
. Check the R console for errors, and review the rendered website.withr::with_envvar(new = c("NOT_CRAN" = "true"), covr::report())
. Begin in a fresh R session without any packages loaded.usethis::use_spell_check()
runs with no spelling errors in documentationWhen the branch is ready to be merged into master:
NEWS.md
with the changes from this pull request under the heading "# ggsurvfit (development version)
". If there is an issue associated with the pull request, reference it in parentheses at the end update (seeNEWS.md
for examples).usethis::use_version(which = "dev")
codemetar::write_codemeta()
usethis::use_spell_check()
again