Skip to content

position_dodge() doesn't properly dodge segments #3617

Closed
@clauswilke

Description

@clauswilke

See related discussion on SO. position_dodge() doesn't dodge the xend aesthetic and as a consequence segments can't be dodged. In the reprex below, the desired effect is to connect the points of identical color within each group.

library(tidyverse)

set.seed(1234)

df <- tibble(
    group = rep(letters[1:3], each = 2),
    subgroup = rep(c("A", "B"), 3)
  ) %>%
  mutate(
    start = rpois(6, 10),
    end = start + rpois(6, 3)
  )

ggplot(df) +
  geom_point(
    aes(group, start, color = subgroup),
    position = position_dodge(width = 1)
  ) +
  geom_point(
    aes(group, end, color = subgroup),
    position = position_dodge(width = 1)
  ) +
  geom_segment(
    aes(x = group, xend = group, y = start, yend = end, color = subgroup),
    position = position_dodge(width = 1)
  ) +
  coord_flip()

Created on 2019-11-08 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorpositions 🥇

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions