mjskay / tidybayes

Bayesian analysis + tidy data + geoms (R package)
http://mjskay.github.io/tidybayes
GNU General Public License v3.0
718 stars 59 forks source link

Make stat_interval provide width automatically for position='dodge' #180

Closed lindeloev closed 5 years ago

lindeloev commented 5 years ago

I love stat_interval and would like to use it for some ordinary non-MCMC data. It says in the doc that it takes the position argument, but AFAICS, it does not respect it. I would expect two stat_intervals on this plot because of the grouping on x:

# Make some data which is two normals on x and bimodal on x2
df = data.frame(x = rep(c('A', 'B'), 30), 
                x2 = rep('A', 60),
                y = c(x = c(rnorm(30, 0), rnorm(30, 5))))

# Plot it, grouped by x
ggplot(df, aes(x=x2, y=y, group=x)) + 
    stat_interval(position='dodge')

Current result: image

So there's only one interval, and that behaves weird in the edges (here, the top).

mjskay commented 5 years ago

Ah, yeah, good point. A workaround is to provide the width used to calculate the dodge manually with something like position = position_dodge(width = .1) (adjust the width to your taste), but some reasonable width should definitely be provided automatically based on the width of the geom.

mjskay commented 5 years ago

TODO:

mjskay commented 5 years ago

This is now fixed in the github version. If the default spacing is not to your taste, manually specifying it using position_dodge(width = XXX) also works (and will already work on the current CRAN version).

lindeloev commented 5 years ago

Awesome, thank you!

(Don't know why I didn't see the warning about `width in the current CRAN version)