Skip to content

Feature/spca biplot - #28

Merged
PPaccioretti merged 5 commits into
mainfrom
feature/spca-biplot
Jul 31, 2026
Merged

Feature/spca biplot#28
PPaccioretti merged 5 commits into
mainfrom
feature/spca-biplot

Conversation

@PPaccioretti

Copy link
Copy Markdown
Owner

New plot sPCA function

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.
Copilot AI review requested due to automatic review settings July 31, 2026 12:26
@PPaccioretti
PPaccioretti merged commit a86127f into main Jul 31, 2026
7 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (including scores) 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 thread R/spca_biplot.R
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 thread R/spca_biplot.R
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 thread R/kmspc.R
Comment on lines 237 to 241
seq_len(Position(
function(x) {
x > explainedVariance
},
unlist(propvaracum_ms)
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

Successfully merging this pull request may close these issues.

2 participants