ggdesplot(): leave cells with a missing value empty - #18
Merged
Conversation
The gg path filled a missing value with grey50, which is hard to tell from the lightgray midpoint of the default RedGrayBlue scale, so a hole in the field read as a mid-range value. The lattice path leaves such a cell empty; set na.value on both fill scales to match it.
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.
Problem
desplot()leaves a cell whose value is missing empty,ggdesplot()fills it with theggplot2 default
grey50. That is not a neutral colour here: the defaultRedGrayBluescaleruns
firebrick->lightgray->#375997, so grey is what the middle of the data rangelooks like, and a hole in the field reads as an average value rather than as no data. With a
factor response the grey cell is a fill that the key has no entry for.
Reproducer
besag.metis the dataset the vignette uses. 36 of its 1188 plots have no yield, and the ggpath drew every one of them grey (desplot 1.11,
b18cfbb):The grey is hard to tell from data in that map, because the mid-range cells are themselves
grey (
#D3D1D1and#C1C5CChere).The vignette draws this dataset with
desplot()rather thanggdesplot(), so no rendereddocumentation changes.
Before / after
ggdesplot(besag.met, yield ~ col * row | county), rendered againstmainand against thisbranch. There are six missing plots in each of the six counties, so every panel is affected.
Before (
main), 36 plots filledgrey50:After (this branch), the same 36 plots left empty:
Fix
na.value = "transparent"on both fill scales,scale_fill_gradientn()for a numericresponse and
scale_fill_manual()for a factor. The gg panel background iselement_blank(), so a transparent cell comes out white, which is what the lattice pathdraws. The observed cells are unchanged, so the fix touches the missing cells only and does
not shift the scale.
Regression test added to
tests/testthat/test_ggdesplot_fixes.R. It covers both the numericand the factor branch on a small synthetic field, and it also pins that the remaining cells
still get a real colour, so an empty cell cannot come from a broken scale instead. On
mainit fails (4 failures, the 29 existing expectations pass), with the fix the suite is 33
passing, 0 failures, 0 warnings.
R CMD check --no-manualincluding the vignette rebuild isStatus: OK.Prepared with the help of an AI coding assistant; the reproducers above were run and
verified locally.