mjskay / ggdist

Visualizations of distributions and uncertainty

Home Page:https://mjskay.github.io/ggdist/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

p_limits argument not used

qrtmnopa197 opened this issue · comments

Hello!

Many ggdist functions appear to ignore the value assigned to p_limits. I have passed values to p_limits using stat_eye, stat_halfeye, stat_histinterval, and stat_ccdfinterval, and none of the plots are affected by the value that is passed. I have tried this using both my data/code and copying and pasting code from the ggdist vignette. For example, the following code (adapted from the vignette) does not limit the distribution in accordance with the p_limits values:

`set.seed(1234)
df = tribble(
~group, ~subgroup, ~value,
"a", "h", rnorm(1000, mean = 5),
"b", "h", rnorm(1000, mean = 7, sd = 1.5),
"c", "h", rnorm(1000, mean = 8),
"c", "i", rnorm(1000, mean = 9),
"c", "j", rnorm(1000, mean = 7)
) %>%
unnest(value)

df %>%
ggplot(aes(y = group, x = value)) +
stat_halfeye(p_limits=c(.4,.5))`

I have the latest versions of tidybayes, R, and RStudio. This error occurs even when tidybayes is the only package loaded.

Hope that's clear! Thanks!

Seconded. I ran into this.

Ah, I don't think I made the intended use of p_limits clear in the documentation. It does not apply to distributions from samples, only to theoretical distributions, where some limits must be chosen in order to determine the range of values to draw the distribution for (when the distribution's limits are not finite). I will update the documentation to reflect this.

That said, what is the use case you have for applying this to sample distributions? Maybe I can help with that.

Thanks for getting back so fast! My use case was comparing stat_halfeye distributions. If the slab extends the entire spread it makes it difficult to see differences in the summary point. I ended up just laying out quantile limits by hand to achieve this but my fast read of p_limits was that it could serve that purpose. Thanks for clarifying!

image

Then with upper_lim <- quantile(performance$crps_mean, 0.95) and + lims(y = c(0, upper_lim))

image

I see. Let me think about whether p_limits (or something else) would be useful here.

In the meantime, I should point out that you should not use lims() / xlim() / ylim() / scale_y_continuous(limits = ...) to adjust limits in this way, as those methods delete data, which will change the calculation of summary statistics like intervals. This is an unfortunately easy mistake to run into that is a flaw in the ggplot2 design (it's a known problem and I think the only reason those functions haven't been deleted is backwards compatibility). You should almost always use coord_cartesian(ylim = ...) instead, as this will "zoom in" without deleting data.

Thanks!