mjskay / tidybayes

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

geom_halfeyeh in tutorial example gives error #161

Closed MCMaurer closed 5 years ago

MCMaurer commented 5 years ago

Hi there,

I've been trying out some of the examples from the tidybayes brms tutorial, and using geom_halfeyeh() in the following code:

m %>%
  spread_draws(b_Intercept, r_condition[condition,]) %>%
  mutate(condition_mean = b_Intercept + r_condition) %>%
  ggplot(aes(y = condition, x = condition_mean)) +
  geom_halfeyeh()

generates the following error:

Warning message:
Computation failed in `stat_xdensity()`:
Please use `to_lower_ascii()`, which works fine in all locales. 

I can create a reasonable facsimile of the half eye plots using the following code:

m %>%
  spread_draws(b_Intercept, r_condition[condition,]) %>%
  mutate(condition_mean = b_Intercept + r_condition) %>%
  ggplot(aes(y = condition, x = condition_mean)) +
  geom_density_ridges(scale = 0.5, rel_min_height = 0.01) +
  stat_pointintervalh()

Thanks for the awesome package, this tutorial I'm working through has been wonderful!

mjskay commented 5 years ago

I haven't been able to reproduce the bug locally. Could you give me a little more information so I can try to reproduce it myself or figure out what's causing it? Two things that might help would be the output of sessionInfo() and if you could give me the output of traceback() after the error happens. Thanks!

mjskay commented 5 years ago

Hi @MCMaurer, are you still having trouble with this bug? I'd love to be able to help if I can, but I would need more info to do so (see my previous message).

MCMaurer commented 5 years ago

Hey @mjskay, so sorry for the delay on this- I'm currently traveling in Europe, but this is on my to-do list as soon as I get back home! Definitely want to help you figure this one out!

mjskay commented 5 years ago

Great, thanks! When you do, could you update all of your packages before testing again to make sure you're on the latest versions of everything?

ferberkl commented 5 years ago

Hi @mjskay , I'm getting the same warning. The resulting plot has the intervals but not the densities:

sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.1

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] tidybayes_1.0.4    scales_1.0.0       brms_2.8.0         Rcpp_1.0.1         readxl_1.3.1      
 [6] forcats_0.4.0      stringr_1.4.0      dplyr_0.8.0.1      purrr_0.3.2        readr_1.3.1       
[11] tidyr_0.8.3        tibble_2.1.1       ggplot2_3.1.0.9000 tidyverse_1.2.1   

loaded via a namespace (and not attached):
 [1] nlme_3.1-137              matrixStats_0.54.0        xts_0.11-2               
 [4] lubridate_1.7.4           threejs_0.3.1             httr_1.4.0               
 [7] rstan_2.18.2              tools_3.5.1               backports_1.1.3          
[10] R6_2.4.0                  DT_0.5                    lazyeval_0.2.2           
[13] colorspace_1.4-1          withr_2.1.2               prettyunits_1.0.2        
[16] tidyselect_0.2.5          gridExtra_2.3             processx_3.3.0           
[19] Brobdingnag_1.2-6         compiler_3.5.1            cli_1.1.0                
[22] rvest_0.3.2               arrayhelpers_1.0-20160527 xml2_1.2.0               
[25] shinyjs_1.0               labeling_0.3              colourpicker_1.0         
[28] dygraphs_1.1.1.6          mvtnorm_1.0-10            ggridges_0.5.1           
[31] callr_3.2.0               StanHeaders_2.18.1        digest_0.6.18            
[34] base64enc_0.1-3           pkgconfig_2.0.2           htmltools_0.3.6          
[37] htmlwidgets_1.3           rlang_0.3.1               rstudioapi_0.10          
[40] shiny_1.2.0               svUnit_0.7-12             generics_0.0.2           
[43] zoo_1.8-4                 jsonlite_1.6              crosstalk_1.0.0          
[46] gtools_3.8.1              inline_0.3.15             magrittr_1.5             
[49] loo_2.1.0                 bayesplot_1.6.0.9000      Matrix_1.2-16            
[52] munsell_0.5.0             abind_1.4-5               stringi_1.4.3            
[55] yaml_2.2.0                ggstance_0.3.1            pkgbuild_1.0.3           
[58] plyr_1.8.4                grid_3.5.1                parallel_3.5.1           
[61] promises_1.0.1            crayon_1.3.4              miniUI_0.1.1.1           
[64] lattice_0.20-38           haven_2.1.0               hms_0.4.2                
[67] ps_1.3.0                  knitr_1.22                pillar_1.3.1             
[70] igraph_1.2.4              markdown_0.9              shinystan_2.5.0          
[73] reshape2_1.4.3            stats4_3.5.1              rstantools_1.5.1         
[76] glue_1.3.1                modelr_0.1.4              httpuv_1.5.0             
[79] cellranger_1.1.0          gtable_0.2.0              assertthat_0.2.1         
[82] xfun_0.5                  mime_0.6                  xtable_1.8-3             
[85] broom_0.5.1               coda_0.19-2               later_0.8.0              
[88] rsconnect_0.8.13          shinythemes_1.1.2         bridgesampling_0.6-0     

data(RankCorr, package = "tidybayes")
 RankCorr %>%
     spread_draws(u_tau[i]) %>%
     ggplot(aes(y = i, x = u_tau)) +
     geom_eyeh()

Warning message:
Computation failed in `stat_xdensity()`:
Please use `to_lower_ascii()`, which works fine in all locales

traceback()
No traceback available 
mjskay commented 5 years ago

Thanks for the extra info!

You appear to be running the dev version of ggplot2 from github. From what I can tell this looks like it might be a bug in the ggstance package introduced by a change in the dev version of ggplot2. I was able to reproduce the bug with the following code by installing the github version of ggplot2:

library(ggplot2)
library(ggstance)

ggplot(data.frame(x = rnorm(1000), y = "a"), aes(x, y)) +
  geom_violinh()

The bug goes away if you downgrade to the release version of ggplot2 on CRAN; e.g. by doing something like this:

install.packages("ggplot2")

I filed a bug for this issue on the ggstance repository: https://github.com/lionel-/ggstance/issues/30

When that bug is fixed I expect this one to resolve. I'll leave this one open for now in case it is helpful to others (and to remind me to check back on the other one).

ferberkl commented 5 years ago

Thanks, @mjskay! I confirmed that installing the CRAN version of ggplot2 worked for me

mjskay commented 5 years ago

Great! :)

esalves commented 5 years ago

@mjskay, I got stuck with the same error just today. I am using the most recent version of R (3.6.0), and ggplot2 (3.2.0). I had to roll back to ggplot2 3.1.0 in order to get geom_halfeyeh() to print the density plots without the error message described by @MCMaurer.

mjskay commented 5 years ago

It looks like this is fixed on the dev version of ggstance. Try doing this and see if it works now:

devtools::install_github("lionel-/ggstance")

I've also changed the github version of tidybayes to now depend on the github version of ggstance (until new ggstance hits CRAN), so another option is to install the github version of tidybayes, which should ask you to install the github version of ggstance and make everything work:

devtools::install_github("mjskay/tidybayes")
esalves commented 5 years ago

Thanks for the hints, @mjskay ! Will do.

mjskay commented 5 years ago

The new version of ggstance that fixes these problems is now on CRAN, so for anyone who encounters this problem now, updating to the latest versions of tidybayes and ggstance should fix it (e.g. running update.packages())