Could position_dodge(preserve = 'single') centre bars/boxs where not all categories are present like in dodge2?
Open
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
Might not be possible, but thought I'd chuck it up just in case
See how waterpolo and gymnastics categories are treated in dodge. I'd prefer they were centred like in dodge2
library(tidyverse)
library(patchwork)
sports <- c("water polo", "swimming", "gymnastics", "field", "netball")
p1 <- ggridges::Aus_athletes |>
dplyr::filter(sport %in% sports) |>
ggplot(aes(height, sport, fill = sex)) +
geom_boxplot(position = position_dodge(preserve = "single")) +
labs(title = "position_dodge(preserve = 'single')") +
theme(legend.position = "none")
p2 <- ggridges::Aus_athletes |>
dplyr::filter(sport %in% sports) |>
ggplot(aes(height, sport, fill = sex)) +
geom_boxplot(position = position_dodge2(preserve = "single")) +
labs(title = "position_dodge2(preserve = 'single')") +
theme(legend.position = "none")
p1 / p2

Created on 2025-09-15 with reprex v2.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with ggplot2's position_dodge(preserve = "single") and position_dodge2(preserve = "single") using the supplied Aus_athletes data and geom_boxplot calls. Start by tracing the two position functions and compare their handling of missing categories; done means position_dodge centres the remaining bars or boxes consistently with position_dodge2 in this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100