Skip to content
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

stat_interval fails with log transformation #168

Closed
qdread opened this issue Jan 25, 2023 · 3 comments
Closed

stat_interval fails with log transformation #168

qdread opened this issue Jan 25, 2023 · 3 comments

Comments

@qdread
Copy link

qdread commented Jan 25, 2023

I am not sure which package updates have caused this breaking cahnge, but I recently noticed some code I wrote a few months ago is now broken due to some unexpected behavior of stat_interval() if there is a log scale axis. For some reason making the axis scale logarithmic causes the computation of stat_interval() to fail, somewhere along the line a non-numeric argument is passed to log().

Here is a reprex I made (edited the post to make the reprex a lot more minimal). Thanks in advance for your help (and for the great packages!)

library(ggplot2)
library(ggdist)

foo <- data.frame(grp = rep(letters[1:3], 1000), stuff = rlnorm(3000))

ggplot(foo, aes(x=grp, y=stuff)) + stat_interval() # Looks as expected
ggplot(foo, aes(x=grp, y=stuff)) + stat_interval() + scale_y_log10() # Fails

The warning returned by ... + scale_x_log10():

Warning message:
Computation failed in `stat_interval()`
Caused by error in `log()`:
! non-numeric argument to mathematical function 

Session info:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggdist_3.2.0  ggplot2_3.4.0
@mjskay mjskay closed this as completed in 182b1d3 Jan 26, 2023
@mjskay
Copy link
Owner

mjskay commented Jan 26, 2023

Thanks for catching this and for the straightforward reprex! Made it easy to isolate the bug. It should be fixed on master now; if you install the github version via remotes::install_github("mjskay/ggdist") you can double-check to make sure the fix works for you.

Thanks again!

@qdread
Copy link
Author

qdread commented Jan 26, 2023

Thanks for addressing this so quickly! Curious whether it was caused by some change in ggplot2 v3.4?

@mjskay
Copy link
Owner

mjskay commented Jan 26, 2023

Nah, it was entirely my fault :). In ggdist 3.2.0 I introduced a feature that shares some computation across slab and interval sub-geometries so that (e.g.) you can use .width and level aesthetics in after_stat() in slabs. This introduced a bug where if the slab is not present at all (as in stat_interval()) if the scale transformation function doesn't like NULLs it will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants