-
Notifications
You must be signed in to change notification settings - Fork 2k
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
and geom_qq_line
always stop at the limits, regardless of other settings?
#6081
Comments
I think the behavior of I'm less certain what |
My logic is that you always want ablines and qq_lines to fall within the plot, but you .want flexibility in how to apply the coord_cartesian clip for the other geoms. The clipping within coord_cartesian relates to all layers. So it can be helpful if you have the freedom to clip layers without affecting qq_lines and ablines (and hlines/vlines). For example, you might want a scatter plot with set limits and a point might land on the outer limit. If you use "clip = off", this is nice because it keeps these points on the limits whole. But then if you add a abline/qq_line, you are forced to change something, because it will exceed the boundaries of the plot |
qq lines span the data. I think it's Ok that the lines extend beyond the plot panel if you force data to fall outside of it as well. (Btw., this seems like a very contrived example to me. Who would do this outside of a bug report? Can you provide an actual example where this is a problem?) ablines should probably be clipped to the plot panel, just like hlines and vlines. Btw., you can force qq lines to be clipped to the panel by setting library(tidyverse)
library(palmerpenguins)
penguins |>
ggplot() +
coord_cartesian(clip = "off") +
scale_x_continuous(limits = c(-2, 2), oob = scales::oob_keep, expand = c(0, 0)) +
scale_y_continuous(limits = c(2000, 6500), oob = scales::oob_keep, expand = c(0, 0)) +
geom_qq(aes(sample = body_mass_g)) +
geom_qq_line(aes(sample = body_mass_g), colour = "red", fullrange = TRUE) +
theme(plot.margin = margin(r = 100))
#> 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()`). Created on 2024-09-05 with reprex v2.1.1 |
Interesting, re Maybe a better example/use-case.. A common thing to do is to set the limits of the plot to get rid of part of a qq_line (or abline). However, users will have to understand how the oob argument works for them to be able to actually achieve this. The oob concept and argument is not widely known/understood - and this could cause confusion. It'd be nicer if it worked in this case without having to know about this. In essence, I feel qq_line and abline are just the same as vline/hline in that you always want it only in the panel. library(tidyverse)
library(palmerpenguins)
penguins |>
ggplot(aes(sample = body_mass_g)) +
geom_qq() +
geom_qq_line(colour = "red")
#> 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()`). penguins |>
ggplot(aes(sample = body_mass_g)) +
geom_qq() +
geom_qq_line(colour = "red") +
scale_y_continuous(limits = c(2500, 6500), expand = c(0, 0))
#> 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()`).
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_path()`). penguins |>
ggplot(aes(sample = body_mass_g)) +
geom_qq() +
geom_qq_line(colour = "red") +
scale_y_continuous(limits = c(2500, 6500), expand = c(0, 0), oob = scales::oob_keep)
#> 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()`). Created on 2024-09-06 with reprex v2.1.1 |
Just as a note; the reason |
@teunbrand I think the point here is that @davidhodge931 I feel we're discussing two entirely different things here. Could you close this issue and open two new ones, one for |
@davidhodge931 Looking over your last set of examples, do I understand that here the problem is the line disappears entirely? If that's the issue then I agree this is a problem and we should discuss strategies to avoid it. But again, as I said in my other comment, entirely different from the |
Could
geom_abline
andgeom_qq_line
always stop at the limits, regardless of other settings?So kind of act in the same way that
geom_hline
/geom_vline
behave.Created on 2024-09-06 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: