aifimmunology / MOCHA

R package for single-cell Open Chromatin Identification & Downstream Analysis
https://aifimmunology.github.io/MOCHA/
GNU General Public License v3.0
2 stars 0 forks source link

plotRegion dimension error when plotting many groups #49

Closed lokada-aifi closed 2 months ago

lokada-aifi commented 2 years ago

Observed the following error when using plotRegion() on a grouped counts object (9 groups). Also observed in other datasets when plotting larger numbers of groups (MP).
Call:
options(repr.plot.width =10, repr.plot.height = 5)
scMACS::plotRegion(proj_counts2, motifSetName = 'Motifs', relativeHeights =c(Chr = 0.9, 'Normalized Counts' = 4, Links = 1.5, Genes = 2, AdditionalGRanges = 4.5))

Error Message:
Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), : Viewport has zero dimension(s)

Fix:
Was able to plot without error by increasing plot height dimensions (external to the plotting function) and/or modifying the relativeHeights argument to allocate more plotting space to the per-group normalized count plots (e.g. relativeHeights = c(Chr = 0.9, 'Normalized Counts'=7, Genes = 2)). Note: excluding the motif labels (motfiSetName = NULL) also allowed the plot to render, but I still believe this to be a dimensions issue where the graph is not able to accommodate the additional data within the allocated space.

With the default plotRegion() settings, this error will be more likely to occur in datasets that have a larger number of groups or possibly a larger number of extra tracks. Can we improve to mitigate errors and/or provide better guidance for users? Note that plot dimensions are dependent on user's graphics device settings, so it may be difficult to completely optimize formatting from with the function while maintaining the function's (intended) flexibility.

markphillippebworth commented 2 years ago

Thank you for tracking that down. We probably need to run some similations to figure out a rough threshold, and then code it in. Or maybe we just have plot region spread the tracks across multiple pdfs if it passes a threshold?

lokada-aifi commented 2 years ago

I wonder if saving to pdf should just be part of the function, included as an optional but default argument (savePDF = TRUE, filename = 'plotRegion.pdf'). That would give us more control in creating a readable default output while still enabling flexibility. In that case, we can either plot everything together and increase the figure size as necessary, or we can go with the split-plot idea with a parameterized default threshold. If we don't output the pdf automatically, then I guess we would be optimizing the split plot # based on default 7x7 plot dimensions?

imran-aifi commented 2 years ago

If a solution involves setting/changing user's graphics options, it should be done with https://withr.r-lib.org/ e.g. https://withr.r-lib.org/reference/with_par.html so that the original state (original options) is restored when this function exits.

SamirRachidZaim-AIFI commented 2 years ago

Potential fixes

markphillippebworth commented 2 months ago

We've re-written how MOCHA handles plotting, so graphics are no longer handled by ggbio. This error should hopefully be resolved, and I'm closing it. Let me know if it occurs again.