Skip to content

position_dodge() doesn't seem to work whex x-axis is a date #6817

@clayford

Description

@clayford

I think I found a problem with position_dodge() when the x-axis is a date.

When creating a bar plot with dodged groups and a date on the x-axis, I am unable to place counts above the bars like the example provided in the geom_text() documentation.

Here is the code to reproduce the bug:

df <- data.frame(
  date <- as.Date(c("2025-01-01", "2025-01-01",
                    "2025-02-01", "2025-02-01")),
  y = c(1, 3, 2, 1),
  grp = c("a", "b", "a", "b")
)

ggplot(data = df, aes(date, y, group = grp)) +
  geom_col(aes(fill = grp), position = "dodge") +
  geom_text(aes(label = y), position = position_dodge(0.9))

I am using ggplot2 version 4.0.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions