Skip to content

Conversation

yutannihilation
Copy link
Member

Reopen #4286, which aimed to fix #4285.

As suggested by @teunbrand, I confirmed now the code works without the as.numeric() tweak if I merge the changes of #5640.

mydata <- data.frame(
  x = factor(c("1", "2", "3")),
  y = c(3, 4, 5)
)
mydata$splits <- factor(mydata$x, labels = c("baseline", "Cycle 1", "Cycle 1"))

devtools::load_all("~/GitHub/ggplot2/")
#> ℹ Loading ggplot2
pos <- position_nudge(x = -0.1)

# works
ggplot(mydata, aes(x, y)) +
  geom_point(size = 3, position = pos) +
  geom_vline(
    aes(xintercept = as.numeric(x)),
    alpha = 0.2, linewidth = 5,
    colour = "red",
    position = pos
  )

# didn't work, but now works!
ggplot(mydata, aes(x, y)) +
  geom_point(size = 3, position = pos) +
  geom_vline(
    aes(xintercept = x),
    alpha = 0.2, linewidth = 5,
    colour = "red",
    position = pos
  )

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

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

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

Thanks for this, it looks good to me!
If you'd like, feel free to add a news bullet

@yutannihilation
Copy link
Member Author

Thanks! Added a news bullet.
I think this should be merged after #5640 gets merged because the soundness relies on it, but please feel free to merge early if you want.

@yutannihilation
Copy link
Member Author

Now that #5640 got merged 🎉 , I think we can merge this.

@yutannihilation yutannihilation merged commit fb33e26 into tidyverse:main Jul 8, 2024
@yutannihilation yutannihilation deleted the fix/issue-4285-vline-hline-position-arg branch July 8, 2024 09:14
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.

Feature request: Add position argument to geom_vline and geom_hline
2 participants