feat(plots): standardize output figures across MOSuite function calls#223
feat(plots): standardize output figures across MOSuite function calls#223phoman14 wants to merge 28 commits into
Conversation
Use the MOSuite palette as the hardcoded filter and normalize plot color default, extend short explicit palettes through the selected palette path, and keep random colors as the get_colors_vctr fallback. Update docs, JSON defaults, and focused color/filter/normalize tests.
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #223 +/- ##
==========================================
+ Coverage 79.66% 79.81% +0.15%
==========================================
Files 22 22
Lines 3398 3612 +214
==========================================
+ Hits 2707 2883 +176
- Misses 691 729 +38 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR standardizes MOSuite figure defaults (colors, legend layout, and sizing) so that plots created directly via plotting functions and those produced indirectly by filter_counts(), normalize_counts(), and batch_correct_counts() render consistently (including in downstream capsule workflows).
Changes:
- Introduces deterministic color-resolution helpers (including factor-level / first-observed ordering) and applies them across PCA, histogram, and heatmap plots.
- Adds automatic legend text sizing and top/bottom legend wrapping for dense legends.
- Aligns workflow functions’ plotting defaults/forwarding and expands test coverage + updates docs/JSON defaults.
Reviewed changes
Copilot reviewed 45 out of 47 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test-plot_pca.R | Adds PCA tests for color resolution and wrapped legends. |
| tests/testthat/test-plot_histogram.R | Adds histogram tests for legend wrapping and deterministic color mapping. |
| tests/testthat/test-plot_heatmap.R | Adds heatmap tests for annotation color resolution order. |
| tests/testthat/test-normalize.R | Adds tests ensuring normalize forwards plotting args/default colors. |
| tests/testthat/test-filter.R | Adds tests ensuring filter forwards plotting args/default colors. |
| tests/testthat/test-colors.R | Updates palette expectations; adds tests for resolve_plot_colors(). |
| tests/testthat/test-batch-correction.R | Adds tests ensuring batch correction forwards plotting args/default colors. |
| tests/testthat/_snaps/E2E.md | Updates snapshot output reflecting new default colors_for_plots type. |
| R/plots.R | Adds internal legend sizing/wrapping helpers for ggplot color legends. |
| R/plot_pca.R | Updates PCA defaults; applies deterministic colors + legend layout logic. |
| R/plot_histogram.R | Applies deterministic colors + legend sizing/wrapping to histograms. |
| R/plot_heatmap.R | Uses shared color resolver for heatmap annotations; adjusts palette expansion. |
| R/normalize.R | Aligns normalize defaults and forwards histogram axis/legend settings. |
| R/filter.R | Aligns filter defaults; improves plot saving sizing and forwards plotting args. |
| R/colors.R | Adds MOSuite palette + observed-order helper + resolve_plot_colors(). |
| R/batch-correction.R | Aligns batch-correct plotting defaults/forwarding; adds interactive option. |
| PCA_COLOR_MATCH_NOTES.md | Adds internal design notes for the color-matching changes. |
| NEWS.md | Documents user-facing plotting default changes. |
| man/set_color_pal.Rd | Updates default palette function documentation. |
| man/plot_pca_3d.Rd | Updates color mapping documentation for PCA 3D. |
| man/plot_pca_2d.Rd | Updates defaults + documents legend font sizing and color mapping rules. |
| man/plot_histogram.data.frame.Rd | Documents color mapping rules + auto legend font sizing. |
| man/plot_expr_heatmap.Rd | Documents color mapping rules for heatmap group colors. |
| man/plot_corr_heatmap-data.frame.Rd | Documents color mapping rules for correlation heatmap annotations. |
| man/normalize_counts.Rd | Updates defaults and clarifies color/legend behavior. |
| man/get_colors_vctr.Rd | Updates default palette + ordering behavior documentation. |
| man/get_colors_lst.Rd | Updates default palette documentation. |
| man/filter_counts.Rd | Updates defaults and clarifies color/legend behavior. |
| man/batch_correct_counts.Rd | Updates defaults + documents new forwarded plotting parameters. |
| inst/extdata/json_args/defaults/plot_pca_2d.json | Updates JSON defaults to match new PCA defaults. |
| inst/extdata/json_args/defaults/normalize_counts.json | Updates JSON defaults to match new normalize defaults. |
| inst/extdata/json_args/defaults/filter_counts.json | Updates JSON defaults to match new filter defaults. |
| inst/extdata/json_args/defaults/batch_correct_counts.json | Updates JSON defaults to match new batch-correct defaults. |
| inst/extdata/json_args/common/plot_pca_2d.json | Updates shared JSON defaults for PCA point size. |
| inst/extdata/json_args/common/normalize_counts.json | Updates shared JSON defaults for normalize colors/legend size. |
| inst/extdata/json_args/common/filter_counts.json | Updates shared JSON defaults for filter colors/legend size. |
| inst/extdata/galaxy/2_blueprints/plot_pca_3d.json | Updates blueprint descriptions re: deterministic color assignment. |
| inst/extdata/galaxy/2_blueprints/plot_pca_2d.json | Updates blueprint defaults + descriptions for PCA 2D. |
| inst/extdata/galaxy/2_blueprints/normalize_counts.json | Updates blueprint defaults + descriptions for normalize. |
| inst/extdata/galaxy/2_blueprints/filter_counts.json | Updates blueprint defaults + descriptions for filter. |
| inst/extdata/galaxy/2_blueprints/batch_correct_counts.json | Updates blueprint defaults + descriptions for batch correction. |
| inst/extdata/galaxy/1_mosuite-templates/normalize_counts.json | Updates template default for histogram grouping. |
| inst/extdata/galaxy/1_mosuite-templates/filter_counts.json | Updates template default for histogram grouping. |
| inst/extdata/galaxy/0_nidap-1.0/Normalization_CCBR_.code-template.json | Updates legacy template default for histogram grouping. |
| inst/extdata/galaxy/0_nidap-1.0/Filter_Low_Counts_CCBR_.code-template.json | Updates legacy template default for histogram grouping. |
| inst/extdata/galaxy/0_nidap-1.0/Batch_Correction_CCBR_.code-template.json | Updates legacy template default for histogram grouping. |
| CITATION.cff | Updates a referenced author email. |
Files not reviewed (2)
- man/batch_correct_counts.Rd: Generated file
- man/filter_counts.Rd: Generated file
| return(unname(colorspace::hex(colorspace::LAB(km$centers)))) | ||
| } | ||
|
|
||
| get_mosuite_colors <- function(n, ...) { |
| if (!is.null(names(color_values))) { | ||
| if (all(obs %in% names(color_values))) { | ||
| return(color_values) | ||
| } | ||
| } |
| fill = NA, | ||
| linewidth = 1 | ||
| ), | ||
| axis.ticks = ggplot2::element_line(linewidth = 1), | ||
| legend.text = ggplot2::element_text(size = 18) | ||
| legend.text = ggplot2::element_text(size = legend_font_size), | ||
| aspect.ratio = 1 | ||
| ) + | ||
| ggplot2::coord_fixed(ratio = 1.5) + | ||
| ggplot2::scale_colour_manual(values = color_values) + |
| 1. Accept `color_values` and the observed group labels. | ||
| 2. Preserve existing names when `color_values` is already a named vector for those labels. | ||
| 3. Treat named vectors whose names do not cover the observed groups as palette-label names for compatibility. | ||
| 4. When `color_values` is unnamed, assign names deterministically using first-observed group labels, matching `get_colors_vctr()`. | ||
| 5. Error when there are more observed groups than colors. |
| Implemented helper shape: | ||
|
|
||
| ```r | ||
| resolve_plot_colors(dat, colname, color_values = NULL, palette_fun = grDevices::palette.colors, ...) |
kelly-sovacool
left a comment
There was a problem hiding this comment.
Here's an initial review for changes that definitely need to be made. I'm taking a closer look at the color-picking code locally and will have more suggestions for that soon.
AI notes are removed from file and so not included in .Rbuildignore Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
already skipped on ci (gh actions). this line is redundant. Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Issue should not be skipped locally. If error the issue should be addressed Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Summary
This PR standardizes the appearance of MOSuite output figures across direct plotting calls, workflow calls, and the matching Code Ocean capsules. The intent is that the same data and grouping metadata produce consistent colors, category order, point sizing, and readable legends whether a figure is created by plot_pca_2d(), plot_pca_3d(), plot_histogram(), plot_read_depth(), filter_counts(), normalize_counts(), batch_correct_counts(), or an affected capsule.
Changes
Affected capsule repos from these package changes:
Validation:
Issues
No linked issue.
PR Checklist
(
Strikethroughany points that are not applicable.)