Skip to content

Could geom_qq_line always stop at the limits, regardless of other settings? #6087

Closed
@davidhodge931

Description

@davidhodge931

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions