Skip to content

ggdesplot(): position num/text labels correctly when the formula has no fill variable - #20

Merged
kwstat merged 1 commit into
kwstat:mainfrom
SchmidtPaul:fix-ggdesplot-num-extent
Aug 7, 2026
Merged

ggdesplot(): position num/text labels correctly when the formula has no fill variable#20
kwstat merged 1 commit into
kwstat:mainfrom
SchmidtPaul:fix-ggdesplot-num-extent

Conversation

@SchmidtPaul

Copy link
Copy Markdown
Collaborator

Problem

Following up on your note that ggdesplot(oats35, ~ col+row|block, num=gen) did not look right: with an empty formula left-hand side (no fill variable) ggdesplot() adds no geom_tile, so nothing establishes the ±0.5 cell extent. The num/text labels on the outer cells then sit exactly on the panel border and get clipped, whereas the lattice desplot() reserves that extent regardless of fill.

Reproducer (against the current main)

library(desplot)
oats35 <- agridat::yates.oats
ggdesplot(oats35, ~ col+row|block, num=gen)  # labels clipped at the panel edges
desplot(oats35,   ~ col+row|block, num=gen)  # lattice centres them

The gg panels' x-range collapses to the outer column centres (e.g. [3, 4] for a two-column block), so a label at either column lands on the border.

Fix

Draw an invisible (fill = "transparent") tile grid in the no-fill case, mirroring what the lattice path already does. The extent then reaches half a cell beyond the outer centres and the labels are centred. Guarded by fill.type == "none", so filled plots are untouched. Added a regression test that checks the panel x-range covers the full cell extent and that a tile layer is present.

This branch also folds in a small follow-up to your suppressWarnings() cleanup: the one remaining suppressWarnings() (the deliberate col.regions positional-fallback warning) is now asserted with expect_warning(..., "positional") instead of being hidden.

Related to your comment on the ggdesplot(oats35, ~ col+row|block, num=gen) line in test_desplot.R.

Prepared with the help of an AI coding assistant; the reproducer above was run and verified locally.

With an empty formula LHS (no fill variable) ggdesplot() drew no tile, so the
+-0.5 cell extent was never established and num/text labels on the outer cells
were clipped at the panel border. Draw a transparent tile grid in that case, as
the lattice path already does.

Also assert the deliberate col.regions positional-fallback warning with
expect_warning() instead of hiding it with suppressWarnings().
@kwstat
kwstat merged commit ada8c7e into kwstat:main Aug 7, 2026
1 check passed
@kwstat

kwstat commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Excellent. Thanks.

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