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_qq_line always stop at the limits, regardless of other settings? #6087

Open
davidhodge931 opened this issue Sep 6, 2024 · 5 comments

Comments

@davidhodge931
Copy link

davidhodge931 commented Sep 6, 2024

Following on from #6081

This would be helpful, as qq_line 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. So, In essence, for the same reasons that it is useful for vline/hline/abline, it is also helpful for qq_line.

An example: say a user wants to have y limits on the range of the y data with zero expand - and also not clip any points in half. They cannot do this as far as I am aware, as the qq_line will now extend past the panel.

library(tidyverse)
library(palmerpenguins)

# with default clip = off, points on the limits are cut in half  
p <-  penguins |> 
    ggplot(aes(sample = body_mass_g)) +
    geom_qq() +
    geom_qq_line(colour = "red") +
    scale_y_continuous(limits = range(penguins$body_mass_g, na.rm = T), oob = scales::oob_keep, expand = c(0, 0)) +
    theme(plot.margin = margin(50,50,50,50))

p
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_qq()`).
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_qq_line()`).

# but you cannot turn clip off, as this affects the qq_line
p +
  coord_cartesian(clip = "off")
#> Warning: Removed 2 rows containing non-finite outside the scale range (`stat_qq()`).
#> Removed 2 rows containing non-finite outside the scale range
#> (`stat_qq_line()`).

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

It would also help people new to ggplot2, as they wouldn't get confused when setting limits and the the qq_line disappearing. See example in #6081

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

I still am not sure I fully understand what the request is. Are you asking that geom_qq_line() gets clipped to the vertical extent of the panel?

@davidhodge931
Copy link
Author

davidhodge931 commented Sep 6, 2024

Exactly, that the geom_qq_line always gets clipped to the vertical (and horizontal) extent of the plot. It is treated the same as vline/hline in this respect

@clauswilke
Copy link
Member

Yeah I think the situation is different from vline/hline because those geoms have no data they're referring to and so the panel boundaries are the only logical places to clip, whereas for geom_qq_line() there are additional options that may make sense.

I wouldn't want to make the vertical clipping the default, but I'm not opposed to adding an option that turns it on, similar to fullrange which turns on clipping in the x direction.

@davidhodge931
Copy link
Author

davidhodge931 commented Sep 6, 2024

Seems like the fullrange = TRUE argument should work in both directions (if possible). The help seems to suggest it does...
image

Maybe it should be renamed to clip = "off" etc to make it more intuitive for users unfamiliar with the internals? Not sure if it'd still be too confusing as to how this interplays with coord_cartesian(clip = ...) and scale_*_continuous(oob = ...)

@teunbrand
Copy link
Collaborator

The qq-line is a stat, whereas clipping is more of a geom property. If we swap to geom = "abline", we can fix this along with #6086.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants