Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #5809.

Briefly, it adds an orientation argument to position_dodge() that can be set to "y" in order to dodge vertically if has_flipped_aes() cannot discern an orientation.
In order to make this work, has_flipped_aes() can now take custom default that is returned when other attempts to discern the orientation have been exhausted.

Reprex from the issue:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

df <- data.frame(
  trt = c(1,1,2,2),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
)

dodge <- position_dodge(0.2, orientation = "y")

ggplot(df, aes(resp, trt, colour = group)) +
  geom_linerange(
    aes(xmin = lower, xmax = upper), 
    position = dodge
  ) +
  geom_point(
    aes(group = interaction(group, trt)),
    position = dodge
  )

Created on 2024-04-18 with reprex v2.1.0

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit b0a4a40 into tidyverse:main Apr 29, 2024
@teunbrand teunbrand deleted the dodge_points_vertically branch April 29, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

position_dogev for points

2 participants