Skip to content

Dodge points vertically #5845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 29, 2024
Merged

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
7 of 12 checks passed
@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