-
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
A way to specify defaults for subguide, subsccale and normalize? #225
Comments
Hmm yeah. If I was doing this I would probably either define a custom function like you have, or at least save a subguide and subscale for reuse, like: sg = subguide_outside(title = "density")
sc = subscale_thickness(expand = expansion(c(0, 0.05)))
# later ..
stat_slab(subscale = sc, subguide = sg) But I can see the value of setting at least subguides and subscales globally. Fortunately the function search path for string suffixes passed to those functions already uses the global environment. This made it easy to implement a version of what base ggplot does to allow scale defaults to be set. ggplot lets you set default scales by creating a function with the same name as the default (e.g. You can now set theme_set(
ggdist::theme_ggdist() +
theme(plot.margin = margin(5.5, 5.5, 5.5, 50),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank())
)
# need `ggdist::` for to prevent infinite recursion here
subscale_thickness = ggdist::subscale_thickness(expand = expansion(c(0, 0.05)))
# need theme = theme_ggdist() because otherwise the guide uses the default
# axis theme elements, which are set to blank above
subguide_slab = ggdist::subguide_outside(title = "density", theme = theme_ggdist())
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", normalize = "groups") +
facet_wrap(~prior, scales = "free") I don't think I will provide a similar mechanism for |
Thanks, this works. Ideally it would have been nice to be able to setup that from the theme, but I see your point that this is a ggplot issue, not a ggdist issue. I can set these as global variables from the theme function, but that's not good practice, just like I agree without you that alterin default aestatics can break others code. So I might just go with the wrapper function for stat_slab, which seems the cleanest solution |
Thanks for solving #219. I'm trying to come up with a easier to way to write all of this:
I like this format where the y scale is completely replaced by the thickness scale as it looks more like what I would get from normal use of ggplot2, but I don't want to type all of that, and I would like to also define defaults for our package. Some of the things above I can of course extract into a custom theme:
leading to the more compact:
but I haven't figure out a way to define the subguide, subscale and normalize arguments to use the above settings by default. Of course, I could make a wrapper for stat_slab:
allowing me to use
but I was wondering if there's a way to specify those arguments without making a wrapper function?
(in practice we are making an autoplot() function, for which this doesn't matter, but for myself I want to leave the option for more control while still using defaults I like)
The text was updated successfully, but these errors were encountered: