r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
172 stars 27 forks source link

Wrong axis title with `trans="log10"` and `scale_x_units` #323

Closed bart1 closed 1 year ago

bart1 commented 1 year ago

This issue is based on : https://github.com/thomasp85/ggforce/issues/227 In the example below the axis title should have the units [m] and not [lg(re 1 m)]

require(units)
#> Loading required package: units
#> udunits database from /usr/share/xml/udunits/udunits2.xml
require(ggplot2)
#> Loading required package: ggplot2
d<-data.frame(a=set_units(1:10,"m"))
ggplot(d, aes(y=a,x=a))+geom_point()+scale_x_units(trans='log10')

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=nl_NL.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggplot2_3.3.6 units_0.8-0  
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9        pillar_1.8.1      compiler_4.2.1    highr_0.9        
#>  [5] R.methodsS3_1.8.2 R.utils_2.12.0    tools_4.2.1       digest_0.6.29    
#>  [9] evaluate_0.16     lifecycle_1.0.1   tibble_3.1.8      gtable_0.3.0     
#> [13] R.cache_0.16.0    pkgconfig_2.0.3   rlang_1.0.4       reprex_2.0.2     
#> [17] DBI_1.1.3         cli_3.3.0         rstudioapi_0.13   yaml_2.3.5       
#> [21] xfun_0.32         fastmap_1.1.0     dplyr_1.0.9       withr_2.5.0      
#> [25] styler_1.7.0      stringr_1.4.1     knitr_1.39        generics_0.1.3   
#> [29] fs_1.5.2          vctrs_0.4.1       tidyselect_1.1.2  grid_4.2.1       
#> [33] glue_1.6.2        R6_2.5.1          fansi_1.0.3       rmarkdown_2.15   
#> [37] farver_2.1.1      purrr_0.3.4       magrittr_2.0.3    scales_1.2.1     
#> [41] htmltools_0.5.3   assertthat_0.2.1  colorspace_2.0-3  labeling_0.4.2   
#> [45] utf8_1.2.2        stringi_1.7.8     munsell_0.5.0     R.oo_1.25.0

Created on 2022-09-02 with reprex v2.0.2

edzer commented 1 year ago

Nice catch! I wonder whether this can be solved on the units side...

Enchufa2 commented 1 year ago

I think we can address this, but I'll need to dig deeper. Now I'm a bit overloaded preparing materials for my new courses. ;-) But I'll take a look.

bart1 commented 1 year ago

No need to hurry, the issue was open for a while. I just moved it here since the function moved.