add-plot-model-fit#52
Merged
Merged
Conversation
…o plot_model_fit and functions, multi-row test summaries can be selected and plotted. Introduce plot_model_fit_dispatch centralize validation, metric resolution, and type resolution after filtering rows. Make model_fit and compare_model_fit methods thin wrappersthat call dispatcher. Decide default plot based onrow count (bullet single-row, otherwise) and preserve-aware for comparisons.
… model_fit fixtures used by tests to validate plottingbehavior across compare and estimator-only summaries.
…faultvalidate inputs clear
… compute sizes, and bar layoutdensity and pt helpers tune label and tick sizesgroup offsets and widths multi plots
brianmsm
commented
Mar 18, 2026
brianmsm
left a comment
Owner
Author
There was a problem hiding this comment.
📋 Review Summary
This PR introduces a flexible, well-structured plotting system for visualizing single and multi-row model fit summaries. The implementation is comprehensive, but there are a few correctness and architectural issues that need addressing before merging.
🔍 General Feedback
- Excellent test coverage and defensive checks around missing or non-converged metrics.
- The
ggprotoobjects evaluated at the top level will break package loading for users withoutggplot2installed, since it is an optional dependency. - Exact threshold matches (like CFI = 0.90) are currently misclassified into the lower band, which violates standard psychometric conventions.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new plot_model_fit() plotting API to psymetrics, including centralized dispatch/validation and multiple plot styles for model_fit / compare_model_fit summaries, plus supporting metadata and documentation/site updates.
Changes:
- Introduces
plot_model_fit()generic + S3 methods, with helpers for metric/test-mode resolution and plot type defaults. - Persists per-row test metadata on
model_fit/compare_model_fitoutputs to support multi-row filtering and “primary” test selection in plotting. - Adds new test coverage and updates docs/pkgdown/README for the new plotting workflow and revised dependency model (ggplot2 in Imports).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| R/plot_model_fit.R | Adds exported plot_model_fit() generic + default method. |
| R/plot_model_fit-methods.R | Implements dispatcher and the four plot styles (bullet/dots/bars/heatmap). |
| R/plot_model_fit-helpers.R | Adds metric specs, sizing/layout heuristics, custom geoms, and data prep helpers. |
| R/model_fit-lavaan.R | Attaches and exposes row-level test-role/primary metadata for downstream consumers. |
| R/compare_model_fit.R | Binds per-fit metadata into the combined compare_model_fit table. |
| R/compare_model_estimates-methods.R | Minor namespace qualification change (stats::setNames). |
| tests/testthat/test-plot-model-fit.R | Adds comprehensive tests for defaults, styles, metric ordering, CI handling, and test_mode. |
| tests/testthat/test-sem-support.R | Removes ggplot2 skips (now required dependency). |
| tests/testthat/test-plot-lavaan.R | Removes ggplot2 skips (now required dependency). |
| tests/manual/sem_stress_lavaan.R | Removes manual ggplot2 availability gating. |
| man/plot_model_fit.Rd | New reference documentation for plot_model_fit(). |
| man/plot_factor_loadings.Rd | Updates docs/examples consistent with ggplot2 being required. |
| man/plot.lavaan.Rd | Updates docs/examples consistent with ggplot2 being required. |
| DESCRIPTION | Bumps version to 0.5.0; moves ggplot2 to Imports. |
| NAMESPACE | Exports/registers plot_model_fit S3 methods. |
| NEWS.md | Adds 0.5.0 release notes for plotting + metadata changes. |
| README.md / README.Rmd | Adds plot_model_fit() to positioning and examples; bumps install tag to v0.5.0. |
| index.md | Updates homepage copy, version tag, and roadmap/logo links. |
| _pkgdown.yml | Adds plot_model_fit to reference index; reorders print-method entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.