-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot arithmetic for ggsurvfit? #96
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I wonder if this post can help... |
# FROM HADLEY WICKHAM USING S7 PACKAGE
method(`|`, list(new_S3_class("ggsurvfit"), new_S3_class("ggsurvfit"))) <- function(e1, e2) {
}
method(`|`, list(new_S3_class("ggsurvfit"), new_S3_class("ggplot"))) <- function(e1, e2) {
}
method(`|`, list(new_S3_class("ggplot"), new_S3_class("ggsurvfit"))) <- function(e1, e2) {
} |
This works! Next steps:
library(S7)
library(ggsurvfit)
#> Loading required package: ggplot2
ggsurvfit_S7 <-
new_class("ggsurvfit_S7", properties = list(obj = new_S3_class("ggsurvfit"))
)
method(`|`, list(ggsurvfit_S7, new_S3_class("ggplot"))) <- function(e1, e2) {
"This is ggsurvfit|ggplot"
}
method(`|`, list(new_S3_class("ggplot"), ggsurvfit_S7)) <- function(e1, e2) {
"This is ggplot|ggsurvfit"
}
method(`|`, list(ggsurvfit_S7, ggsurvfit_S7)) <- function(e1, e2) {
"This is ggsurvfit|ggsurvfit"
}
plot1 <- ggsurvfit_S7(
obj = survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
add_risktable()
)
plot2 <- ggplot(mtcars, aes(mpg, cyl)) + geom_point()
plot1 | plot2
#> [1] "This is ggsurvfit|ggplot"
plot2 | plot1
#> [1] "This is ggplot|ggsurvfit"
plot1 | plot1
#> [1] "This is ggsurvfit|ggsurvfit"
method(`|`, list(ggsurvfit_S7, ggsurvfit_S7)) <- function(e1, e2) {
patchwork::wrap_elements(ggsurvfit_build(e1@obj)) | patchwork::wrap_elements(ggsurvfit_build(e2@obj))
}
#> Overwriting method |(<ggsurvfit_S7>, <ggsurvfit_S7>)
plot1 | plot1 Created on 2023-10-10 with reprex v2.0.2 |
UPDATE FOR THE FUTURE DANIEL TO HOPEFULLY NOT FORGET!
`|.ggsurvfit` <- function(e1, e2) {
patchwork::wrap_elements(ggsurvfit_build(e1)) |
patchwork::wrap_elements(ggsurvfit_build(e2))
}
I am hopeful that patchwork will green-light the new generic function suggested in thomasp85/patchwork#310 . Thomas added the feature tag a couple of months ago, hopefully signaling he's open to the suggestion 🤞🏼 |
Hi Daniel, I just watched your presentation on ggsurfvit and it was very well presented! |
Ahhh, very interesting! I need to read up on the new features for the guides! Maybe we can set up a time to chat about the details soon? I couple of potential issues come to mind:
Anyway, would love to chat! |
Nah, you'd be surprised to learn that axis infrastructure is sorta geared towards aligning things at the tick marks 😅
No, patchwork only mops up the non-position guides. Axes should remain in place. Chat sounds great, just drop me an email if you want to propose dates/times! |
Is it feasible to export methods for
+.ggsurvfit
,-.ggsurvfit
,/.ggsurvfit
, etc. They would work just like the patchwork versions, but would callggsurvfit_build()
to first construct the risktable, then pass the objects on to the ggplot2 methods.https://patchwork.data-imaginist.com/reference/plot_arithmetic.html
I did some preliminary testing with a built ggsurvfit figure, and it did not seem to be as straight-forward as I was hoping.
This help file on generics for operators is helpful. The class of both sides of the operator are considered before it's dispatched to a method.
https://stat.ethz.ch/R-manual/R-devel/library/base/html/groupGeneric.html
The text was updated successfully, but these errors were encountered: