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

Move coord clipping responsibility from facet to coord #5953

Merged
merged 11 commits into from
Aug 20, 2024

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Jun 20, 2024

This PR aims to fix #5951 and fix #5952.

Briefly, the solution here is that facets no longer clip panels to their rectangular cells in the gtable, but coords set the appropriate viewport on their panels. This also allows custom behaviour for coord_radial() to use a clipping path instead of rectangle.

Reprex from issue; note that the points in upper quarter are appropriately clipped.

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  scale_x_continuous(limits = c(3, 6), oob = scales::oob_keep) +
  coord_radial(
    start = 0.25 * pi, end = 1.75 * pi, 
    clip = "on"
  )

Created on 2024-06-20 with reprex v2.1.0

Of note, non-rectangular clipping paths are a newer feature in R graphics and are silently ignored prior to R4.1.0.

@teunbrand
Copy link
Collaborator Author

As #5952 was code-adjacent to this PR, i've included a fix for that issue as well. The fix is to set theme(strip.clip = "on") by default and always use that instead of coord clip settings in the strips.

Copy link

@BenVolpe94 BenVolpe94 left a comment

Choose a reason for hiding this comment

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

Seems to work fine for me 👍

@teunbrand
Copy link
Collaborator Author

I'm grateful for the thumbs up @BenVolpe94, but I'm afraid I need the approval of a maintainer to merge a PR 😅

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

@thomasp85
Copy link
Member

Can you add a TODO about adding a unit test for when the time comes and vdiffr supports clipping paths

@teunbrand teunbrand merged commit 995b40c into tidyverse:main Aug 20, 2024
13 checks passed
@teunbrand teunbrand deleted the coord_clip branch August 20, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants