Feature/spca biplot - #28
Merged
Merged
Conversation
kmspc() computed the spatial PCA results and then discarded them unless all_results = TRUE. Tracing the default call: pca_results starts as NULL, the all_results branch is skipped, the !only_spca_results branch is skipped because only_spca_results defaults to TRUE, and spca_results was only attached to pca_results inside the second all_results branch. The function therefore returned pca_results = NULL with default arguments, even though only_spca_results = TRUE is documented as returning precisely those results. The spatial PCA summary and the loadings are now always returned. The site coordinates on the retained components are returned as well, under `scores`; they were already computed as the input of the clustering step but were not exposed, and without them a biplot cannot be drawn. Adds spca_biplot(), which builds the biplot from a kmspc() result and can colour the sites by any of the computed classifications, so that it is possible to see which variables drive the separation between management zones. It returns a ggplot object and guards the ggplot2 dependency, which stays in Suggests. Note: run devtools::document() to regenerate NAMESPACE and the man pages; the export of spca_biplot() is not yet registered.
Files in the working tree used CRLF while the stored blobs use LF, and there was no .gitattributes to mediate. As a result git reported every tracked file as fully modified, which made diffs and pull request reviews unreadable. This commit touches many files but does not change a single line of code. From here on every diff reflects content only.
Generated with roxygen2. Note that man/kmspc.Rd is still the previous version: devtools::document() has to be run again so that the revised @return section of kmspc() reaches its help page.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new spca_biplot() plotting function for visualizing sPCA results produced by kmspc(), and adjusts kmspc()’s returned PCA/sPCA summaries to be consistently expressed as percentages while ensuring sPCA results are always included in pca_results.
Changes:
- Added
spca_biplot()(with docs + example) to draw sPCA biplots and optionally color sites by clustering output. - Fixed/standardized
kmspc()PCA/sPCA explained-variance columns to be percentages and ensured sPCA results (includingscores) are always returned. - Updated package exports/NAMESPACE, NEWS entry, and repo packaging metadata/ignores.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| R/spca_biplot.R | New biplot helper for sPCA scores/loadings with optional clustering-based coloring. |
| R/kmspc.R | Makes sPCA results always present in pca_results, adds scores, and standardizes variance percentages. |
| NEWS.md | Documents the percentage-scale fix, sPCA return fix, and new spca_biplot(). |
| NAMESPACE | Exports spca_biplot() and registers print.multispati / summary.multispati S3 methods. |
| man/spca_biplot.Rd | Generated documentation for spca_biplot(). |
| man/kmspc.Rd | Updated return-value documentation and cross-reference to spca_biplot(). |
| inst/examples/spca_biplot.R | Example usage for the new biplot function. |
| DESCRIPTION | Updates roxygen metadata (adds Config/roxygen2/version). |
| .Rbuildignore | Adds .gitattributes to build ignore and adjusts revdep ignore entry. |
| .gitattributes | Adds line-ending normalization and binary patterns for common spatial/data artifacts. |
Files not reviewed (2)
- man/kmspc.Rd: Generated file
- man/spca_biplot.Rd: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+116
to
+120
| if (is.null(arrow_scale)) { | ||
| max_site <- max(abs(c(sites$axis_x, sites$axis_y)), na.rm = TRUE) | ||
| max_arrow <- max(abs(c(arrows$arrow_x, arrows$arrow_y)), na.rm = TRUE) | ||
| arrow_scale <- if (max_arrow > 0) 0.85 * max_site / max_arrow else 1 | ||
| } |
Comment on lines
+85
to
+87
| if (length(axes) != 2 || !is.numeric(axes)) { | ||
| stop("'axes' must be a numeric vector of length two", call. = FALSE) | ||
| } |
Comment on lines
237
to
241
| seq_len(Position( | ||
| function(x) { | ||
| x > explainedVariance | ||
| }, | ||
| unlist(propvaracum_ms) |
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.
New plot sPCA function