[ggdesplot] fix spurious colour legend, named-palette fallback, and multi-facet#17
Open
SchmidtPaul wants to merge 1 commit into
Open
[ggdesplot] fix spurious colour legend, named-palette fallback, and multi-facet#17SchmidtPaul wants to merge 1 commit into
SchmidtPaul wants to merge 1 commit into
Conversation
…ulti-facet Three issues in ggdesplot() (the lattice desplot() is unaffected): - A dummy 'no_color' factor leaked in as a visible colour legend whenever 'text' or 'num' was used without 'col'. The colour key is now suppressed unless 'col' is supplied. - The named col.regions / col.text fallback kept vector names, so scale_*_manual() still matched by name and left unmatched levels uncolored. Names are stripped so the documented positional fallback actually applies. - A formula like 'y ~ x*z | a + b' only faceted on the first conditioning variable; the rest were silently dropped and cells overplotted. All conditioning variables are now combined into the panel factor.
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.
These are three independent fixes in
ggdesplot(). The latticedesplot()is not affected by any of them - in each casedesplot()already produces the correct result, andggdesplot()now matches it.All reprexes use
agridat::besag.met/ synthetic data only.1. Spurious
no_colorlegendWhen
textornumis supplied withoutcol, an internal dummy factor (no_color) leaks in as a visible colour legend.Cause: without
col, the code setscol.string = "no_color"; data[[col.string]] <- factor(1)and then unconditionally addsscale_color_manual(). The colour key is now suppressed (guide = "none") unlesscolwas actually supplied.2. Named
col.regions/col.textfallback leaves cells uncoloredWith a partial named palette, the warning promises "falling back to positional matching", but unmatched levels are drawn grey.
Cause:
rep(col.regions, length = fill.n)kept the vector names, soscale_fill_manual()still matched by name and dropped unmatched levels. Names are now stripped (as.vector()) so the documented positional fallback actually applies. Same fix for thecol.textfallback.3. Only the first conditioning variable was used
A formula with two conditioning variables silently facets on the first only; cells from the dropped factor overplot each other.
Cause:
facet_wrap()usedff$cond[1]only. All conditioning variables are now combined into a single panel factor, so every conditioning variable is faceted. Single-variable formulas keep their original panel labels.Tests for all three are added in
tests/testthat/test_ggdesplot_fixes.R.R CMD checkis clean (0 errors, 0 warnings).Note: these were found during an LLM-assisted bug hunt of
desplot.