Skip to content
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

Feature request: patchwork support #86

Open
mstone-modulus opened this issue Apr 6, 2022 · 2 comments
Open

Feature request: patchwork support #86

mstone-modulus opened this issue Apr 6, 2022 · 2 comments

Comments

@mstone-modulus
Copy link

mstone-modulus commented Apr 6, 2022

Hi,

Would it be possible to support composing figures produced via autoplot() with patchwork?

Currently, attempting to combine figures results in the following error:

> p1 + p2
Error in if (empty(data)) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In class(x) <- c("patchwork", class(x)) :
  Setting class(x) to multiple strings ("patchwork", "ggcyto_flowSet", ...); result will no longer be an S4 object

I've found that I can use ggcyto_arrange() and gridExtra as a workaround when applying autoplot() to GatingHierarchy objects. For example, when wishing to view multiple gates across all samples in a GatingSet.

nodes <- c("nonDebris", "lymph")

gts <- lapply(gs, function(gh) {
  res <- autoplot(gh, nodes, bins=32, strip.text="gate")
  gt <- ggcyto_arrange(res, nrow=1)
})

p <- do.call(gridExtra::gtable_rbind, gts)
plot(p)

However, I can't use this approach when applying autoplot() to flowFrame objects (e.g. when replicating the 1D and 2D gating plots in the auto gating demo).

fr <- gh_pop_get_data(gs[[1]], "lymph")
chnl <- "Live"
g <- openCyto:::.tailgate(fr, channels = chnl, tol = 0.05)
p1 <- autoplot(fr, chnl) + geom_gate(g)
p2 <- autoplot(fr, chnl, "SSC-A") + geom_gate(g)

From what I can tell, this is because ggcyto_arrange() requires a ggcyto_GatingLayout, which autoplot() returns when applied to a GatingSet but not when applied to a flowFrame.

## res <- autoplot(gh, ...)
> is(res)
[1] "ggcyto_GatingLayout" "list"               
[3] "vector"              "AssayData"          
[5] "list_OR_List"        "vector_OR_Vector"   
[7] "vector_OR_factor" 

## p1 <- autoplot(fr, ...)  
> is(p1)
[1] "ggcyto_flowSet" "ggcyto"         "gg"            
[4] "ggplot"         "oldClass"     

Would it be possible to make the return type of autoplot() consistent across inputs? And is there a straightforward way to cast a list of ggcyto_flowSet objects to ggcyto_GatingLayout? I thought supporting patchwork might be the easiest way to support this kind of figure composition in the long run, but I'm happy to continue using the gridExtra workaround until it can be implemented.

Thanks!

Matt

@mstone-modulus
Copy link
Author

edit: Casting to ggplot appears to solve this. Is there any reason why this might present an issue in practice?

as.ggplot(p1) + as.ggplot(p2)

@malcook
Copy link

malcook commented Sep 16, 2024

edit: Casting to ggplot appears to solve this. Is there any reason why this might present an issue in practice?

#67 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants