-
Notifications
You must be signed in to change notification settings - Fork 26
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
do not limit range of brakes in subguide_axis #219
Comments
This filtering is necessary because Base ggplot2 scales do the same thing; e.g.: ggplot() +
geom_point(aes(x = 1:5, y = 1:5)) +
scale_x_continuous(breaks = -10:10) To adjust the limits manually, you can set library(ggplot2)
library(ggdist)
library(dplyr)
data.frame(prior = c("normal(0,1)", "normal(0,2)")) %>%
parse_dist(prior) %>%
ggplot(aes(xdist = .dist_obj, color = prior)) +
stat_slab(fill = NA, subguide = subguide_outside(title = "density",
breaks = seq(0,1,0.1))) +
scale_thickness_shared(limits = c(0,0.4)) +
ylab(NULL) +
theme_ggdist() +
theme(plot.margin = margin(5.5, 5.5, 5.5, 50),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) |
Unfortunately that's not a great solution for the following reasons:
These two issues unfortunately prevent me from using the solution you suggested. However, if I manually change the line
to
I get a much nicer result, without having to specify anything and just using the defaults: ### with manually disabling the source code as described above
data.frame(prior = c("student_t(3,2,0.75)", "normal(0,5)")) %>%
parse_dist(prior) %>%
ggplot(aes(xdist = .dist_obj)) +
stat_slab(fill = NA, color = "red",
subguide = subguide_outside(title = "density"),
normalize = 'groups') +
ylab(NULL) +
theme_ggdist() +
theme(plot.margin = margin(5.5, 5.5, 5.5, 50),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
facet_wrap(~prior, scales = "free") This is because If you say disabling this will break other things, maybe you could consider making a user option ot disable it? The example you give about the default ggplot behavior is actually closer to what I want. Consider this slightly adjusted code: ggplot() +
geom_point(aes(x = 1:5, y = c(1,2,3,4,4.9))) This does not cut-off the break at 5, because the maximum y value is less than that. But in subguide_axis it does. It seems to me that |
Cool! This would be a great thing to have, so I definitely want to figure out something that works. Re-opening.
Heh believe me, it will ;). In fact, this line used to be exactly what you're asking me to change it to. The problem is that because many
What's happening in this example is not that ggplot is adjusting limits based on the breaks, it's that the default expansion parameter of continuous positional scales happens to be large enough that the break outside of the limits is still drawn. You can see that if you don't expand the axis limits: ggplot() +
geom_point(aes(x = 1:5, y = c(1,2,3,4,4.9))) +
scale_y_continuous(expand = expansion(0)) Fundamentally, the problem is that limits should not be determined by the breaks --- by the time breaks come into play, limits have been determined much earlier in the pipeline. If you want the scale to show more breaks, you need a way to expand the limits such that those breaks will be visible. To me this suggests a few possibilities:
More generally, I think the right solution might be to allow people to pass their own scale function to slab geometries that allows customization of both limits and expand arguments. Such a scale would then be applied within the groups determined by the |
Playing with a way to fix this by exposing greater control of sub-scales. Something like this mimics the default position scales by expanding the upper thickness limit by 5%: ggplot() +
stat_slab(
aes(xdist = dist_normal()),
subguide = subguide_inside(title = "density"),
subscale = subscale_thickness(expand = expansion(c(0, 0.05)))
) Check out the Note that, along with this I am considering renaming the |
Cool, thanks for working on that! I'll try to take a look in the next day or two. I just finished the derivatives PR for distributional so I should have some time to get back to this |
Did a bit more tweaking and I'm happy with this for now, so it is merged to master now. I'm closing this, but don't hesitate to re-open if it's not solving your problem; I'm happy to iterate. I also decided I am likely to rename |
Can confirm this solves my problem. Thanks! |
Based on the discussion in #183, I've been trying to plot the density of distributions showing the density on the y axis. The following example works well, but I find it aesthetically displeasing that the breaks get cut-off - the maximum break showed is 0.3, because the max density value is ~0.39. In standard ggplot this is not limited in such a way and you have more control over the breaks. Even if I supply the breaks = seq(0,0.4,0.1), the top break still gets cut-off.
Created on 2024-03-29 with reprex v2.1.0
This is caused by the following line in subguide_axis():
removing this line gives me what I want:
My suggestion is either to get rid of this line, or if you need it for other functionality, to add an argument to subguide_* functions to disable it
The text was updated successfully, but these errors were encountered: