tidyverse / tidyverse/ggplot2

PositionStack (and others) expects a numeric, non factor, "group"

Open Beginner friendly
#6,838 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

positions :1st_place_medal:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

PositionStack and similar classes that use collide() and collide2 to sort the data expects "group" to be numeric, not factor.
Some Stats may create a "factor" group column, though not those which might be stacked (i.e. StatContour), the problem is relevant for custom Stat extensions that might update group.
The problem arises because for reverse = TRUE, the "collide" functions use order(..., -data$group) instead of order(..., data$group, decreasing = TRUE), as "-" is not meaningful for factors.
https://github.com/tidyverse/ggplot2/blob/c02c05aa6303e9592e37289d780224a06be5a27e/R/position-collide.R#L43

ggplot(faithfuld, aes(waiting, eruptions, z = density)) + 
  geom_contour(position = "stack")
# warning "-" no meaningful for factors
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in R/position-collide.R around the linked line and inspect how collide() and collide2 order group when reverse is TRUE. Reproduce the supplied geom_contour example, then verify that factor-valued group data no longer produces the warning and is ordered correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.