Skip to content

Clipping in geom_abline() #6109

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 6 commits into from
Dec 3, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6086.

Briefly, also clips the line to y-limits.

Reprex from #6086 (comment):

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading 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-17 with reprex v2.1.1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note the purple segment at the top is now gone. It should be gone because coord_polar() has 0 y-axis expansions, so it was actually out-of-bounds before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Visually identical, as is the flipped one.

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 73f6bff into tidyverse:main Dec 3, 2024
13 checks passed
@teunbrand teunbrand deleted the geom_abline_clipping branch December 3, 2024 07:33
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.

Could geom_abline always be clipped to panel in both x and y directions?
2 participants