Skip to content
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

Could geom_abline always be clipped to panel in both x and y directions? #6086

Open
davidhodge931 opened this issue Sep 6, 2024 · 1 comment · May be fixed by #6109
Open

Could geom_abline always be clipped to panel in both x and y directions? #6086

davidhodge931 opened this issue Sep 6, 2024 · 1 comment · May be fixed by #6109

Comments

@davidhodge931
Copy link

davidhodge931 commented Sep 6, 2024

Following on from #6081

This would be helpful, as abline is always needed in the panel - and then you would have the flexibility to adjust the scale and coord settings without adversely affecting the abline.

Currently it does on the x, but not on the y.

library(tidyverse)
library(palmerpenguins)

ggplot() +
  geom_abline(colour = "blue", slope = 0.1) +
  geom_abline(colour = "red", slope = 6) +
  scale_x_continuous(limits = c(-2, 2), oob = scales::oob_keep, expand = c(0, 0)) +
  scale_y_continuous(limits = c(-2, 2), oob = scales::oob_keep, expand = c(0, 0)) +
  coord_cartesian(clip = "off") +
  theme(plot.margin = margin(50,50,50,50))

Created on 2024-09-07 with reprex v2.1.1

@davidhodge931 davidhodge931 changed the title Could geom_abline always stop at the limits, regardless of other settings? Could geom_abline always stop at the limits, regardless of other settings? Sep 6, 2024
@clauswilke
Copy link
Member

To be more precise, I think what you're requesting is that geom_abline() is clipped to the plot panel in both the x and the y directions. I think this is a reasonable request.

Slightly simpler reprex:

library(ggplot2)

ggplot() +
  geom_abline(colour = "blue", slope = 0.1) +
  geom_abline(colour = "red", slope = 6) +
  coord_cartesian(clip = "off") +
  xlim(-2, 2) + ylim(-2, 2) +
  theme(plot.margin = margin(50, 50, 50, 50))

Created on 2024-09-06 with reprex v2.0.2

@davidhodge931 davidhodge931 changed the title Could geom_abline always stop at the limits, regardless of other settings? Could geom_abline always be clipped to panel in both x and y directions? Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants