Skip to content

Expose position arg on geom_hline() and geom_vline() #4286

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

Conversation

yutannihilation
Copy link
Member

Fix #4285

@thomasp85
Copy link
Member

Have you tested how this behaves with other positions than position_nudge()? I'm fine with it not working but I could envision some hard-to-understand errors

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@yutannihilation
Copy link
Member Author

yutannihilation commented Mar 25, 2021

Hmm, no. And, sorry, I think I tested this quickly with the similar code to #4285 (comment) and thought it works, but it was probably just I forgot to change as.numeric(x). This needs some more tweaks. I don't see immediately the reason why this doesn't work.

library(ggplot2)

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("~/repo/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, size = 5,
    colour = "red",
    position = pos
  )

# doesn't work
ggplot(mydata, aes(x, y)) +
  geom_point(size = 3, position = pos) +
  geom_vline(
    aes(xintercept = x),
    alpha = 0.2, size = 5,
    colour = "red",
    position = pos
  )
#> Warning in Ops.factor(x, params$x): '+' not meaningful for factors
#> Warning: Removed 3 rows containing missing values (geom_vline).

Created on 2021-03-25 by the reprex package (v1.0.0)

@thomasp85
Copy link
Member

@yutannihilation do you think it is feasible to have this PR done this week? I'm beginning to wrap up the patch release

@yutannihilation
Copy link
Member Author

Sorry, I'm afraid I can't... I thought this was as easy job as just exposing the argument, but it turned this requires a better understanding about how position works, which I don't know yet.

@thomasp85
Copy link
Member

No problem - I've moved all other position related issues to next release because it seems to be a huge work getting it all fixed coherently

@thomasp85 thomasp85 modified the milestones: ggplot2 3.3.4, ggplot2 3.4.0 May 4, 2021
@yutannihilation
Copy link
Member Author

I see, thanks for handling the release!

@hadley
Copy link
Member

hadley commented Mar 15, 2022

@yutannihilation do you still think this is worth finishing off?

@yutannihilation
Copy link
Member Author

Yes, but I don't think I can finish this soon. I'm giving up for now, sorry.

@yutannihilation yutannihilation deleted the fix/issue-4285-vline-hline-position-arg branch March 16, 2022 11:23
@hadley
Copy link
Member

hadley commented Mar 16, 2022

No problems — thanks for giving it a go!

@teunbrand
Copy link
Collaborator

The issue in #4286 (comment) is that xintercept in not a member of scale_x_discrete()$aesthetics. That problem should get fixed by #5640, and this PR improves the lack of position adjustments.

@yutannihilation Is there any chance I could convince you to revive this PR? If you don't have a luxurious amount of free time on your hands I wouldn't mind recreating it anew.

@yutannihilation
Copy link
Member Author

Oh, thanks. I just quit my job today so I only have free time in theory :) Let me try this again. Though I couldn't keep up with the recent evolution of ggplot2, I hope I can adjust myself.

@teunbrand
Copy link
Collaborator

teunbrand commented Jun 28, 2024

I just quit my job today

I hope this was by choice and works out in your favour!

I couldn't keep up with the recent evolution of ggplot2

I'd be glad to help out any way I can, e.g. if you have questions..

There isn't any hurry in this, but I think this PR is the right solution for the problem.

@yutannihilation
Copy link
Member Author

Thanks. It's my choice, so don't worry about me.

I hope I'll start addressing on this next week!

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
4 participants