ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

`position_dodge` not working well with `preserve = "single"` and `geom_text` (or `geom_point`)

Open davidhodge931 opened this issue 1 year ago • 1 comments

In CRAN version, it doesn't manage to dodge the text correctly...

library(tidyverse, quietly = TRUE)
#> Warning: package 'ggplot2' was built under R version 4.4.1
library(palmerpenguins, quietly = TRUE)

penguins |>
  count(species, sex) |>
  ggplot(
    aes(x = sex,
        y = n,
        fill = species,
        label = n),
  ) +
  geom_col(
    position = position_dodge(preserve = "single"),
    width = 0.75,
    alpha = 0.9,
  ) +
  geom_text(
    colour = "black",
    position = position_dodge(width = 0.75, preserve = "single"),
    vjust = 1.33,
  )
#> Warning in max(table(panel$xmin)): no non-missing arguments to max; returning
#> -Inf

Created on 2024-07-12 with reprex v2.1.0

With DEV version downloaded just now, it errors image

davidhodge931 avatar Jul 11 '24 21:07 davidhodge931