Skip to content

Document transKeepSign fully, with examples and tests (#287) - #292

Open
vsimko wants to merge 1 commit into
taiyun:masterfrom
vsimko:fix-287-transKeepSign-docs
Open

vsimko wants to merge 1 commit into
taiyun:masterfrom
vsimko:fix-287-transKeepSign-docs

Conversation

@vsimko

@vsimko vsimko commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

What this changes

The documentation for transKeepSign was cut off mid-sentence — the manual
ended at NOTE: If FALSE, the non-corr matrix will be, which is where the
roxygen block in R/corrplot.R also stops. So the argument was documented by
a sentence that never finished.

This replaces the note with an actual description:

  • With transKeepSign = TRUE (default), values are divided by
    max(abs(col.lim)). They keep their sign and zero stays at the midpoint of
    the palette, so a diverging palette is centred on zero just as it is for a
    correlation matrix. This is the one to use when zero is a meaningful
    reference (differences, log ratios, z-scores).
  • With transKeepSign = FALSE, values are rescaled linearly so that
    col.lim[1] takes the first colour and col.lim[2] the last: the whole
    palette is used over the whole range, at the cost of zero no longer sitting
    in the middle. A sequential palette usually fits better there.
  • Also documented two behaviours that weren't mentioned anywhere: the
    value-based methods (circle, square, ellipse, shade, pie) are
    rejected when the sign is dropped, because the rescaled values are all
    non-negative; and a matrix whose values are all positive or all negative is
    always rescaled linearly over col.lim, whatever the flag says.

No behaviour changes — documentation and tests only.

Files touched

  • R/corrplot.R, man/corrplot.Rd — the rewritten argument description, plus
    an example that plots a non-correlation matrix with col.lim = c(-8, 8)
    both ways.
  • vignettes/example-corrplot.R — the same example for the vignette.
  • tests/testthat/test-corrplot.R — regression test for the documented
    behaviour: value-keeping with TRUE, (x - col.lim[1]) / diff(col.lim) with
    FALSE, the error for glyph methods with FALSE, and the identity for a
    single-sign matrix.
  • NEWS.md — entry under the development version.

Checks

R CMD INSTALL .
testthat::test_dir("tests/testthat")
#> Failed: 0, Warnings: 0, Skipped: 8

(The 8 skips are pre-existing empty test files.)

Fixes #287.

The NOTE: for transKeepSign was cut off in the roxygen block, so the
reference manual explained neither what the argument does when FALSE nor
what the rescaling actually is.

Describe both rescalings: TRUE divides by max(abs(col.lim)) and keeps zero
at the middle of the palette; FALSE spreads the palette linearly over
col.lim. Note that the value-based methods (circle, square, ellipse,
shade, pie) are rejected when the sign is dropped, and that a matrix with
a single sign is always rescaled linearly over col.lim.

Add an example illustrating the two modes, a regression test for the
documented behaviour, and a NEWS entry.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transKeepSign argument of corrplot() documentation is unclear

1 participant