ggrepel icon indicating copy to clipboard operation
ggrepel copied to clipboard

Make more compatible with scale_size_area()

Open sangwon-hyun opened this issue 3 years ago • 1 comments

Summary

When using scale_size_area(), point.size needs to be adjusted, probably by a square root. It seems this should be the default behavior without the user specifying it..

Minimal code example

Here is the minimum amount of code needed to demonstrate the issue:

library(ggplot2)
df <- data.frame(b = exp(seq(3, 4, length = 10)))
ggplot(df, aes(1, b, size = b)) + 
  geom_point() +
  scale_size_area() +
  ggrepel::geom_text_repel(aes(label = round(b,2), point.size = sqrt(b)))

ggplot(df, aes(1, b, size = b)) + 
  geom_point() +
  scale_size_area() +
  ggrepel::geom_text_repel(aes(label = round(b,2), point.size = b))

Here is an image of the output produced by the code:

image image

Suggestions

NA

Version information

Here is the output from sessionInfo() in my R session:

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] reprex_2.0.0       flowmix_0.0.0.9000 testthat_3.0.2     here_1.0.1         cmap4r_0.1.0       knitr_1.33        
 [7] forcats_0.5.1      dplyr_1.0.7        purrr_0.3.4        readr_1.4.0        tidyr_1.1.3        tibble_3.1.2      
[13] ggplot2_3.3.5      tidyverse_1.3.1    stringr_1.4.0     

loaded via a namespace (and not attached):
  [1] readxl_1.3.1             backports_1.2.1          systemfonts_1.0.1        RcppEigen_0.3.3.9.1      sn_2.0.0                
  [6] plyr_1.8.6               lazyeval_0.2.2           sp_1.4-5                 splines_4.1.0            gmp_0.6-2               
 [11] crosstalk_1.1.1          leaflet_2.0.4.1          usethis_2.0.1            digest_0.6.27            foreach_1.5.1           
 [16] htmltools_0.5.1.1        fansi_0.5.0              magrittr_2.0.1           memoise_2.0.0            remotes_2.3.0           
 [21] modelr_0.1.8             svglite_2.0.0            prettyunits_1.1.1        colorspace_2.0-0         ggrepel_0.9.1           
 [26] rvest_1.0.0              haven_2.4.1              xfun_0.24                leafem_0.1.3             callr_3.7.0             
 [31] crayon_1.4.1             jsonlite_1.7.2           RcppArmadillo_0.10.4.0.0 keyring_1.2.0            survival_3.2-11         
 [36] iterators_1.0.13         glue_1.4.2               kableExtra_1.3.4         gtable_0.3.0             webshot_0.5.2           
 [41] clipr_0.7.1              pkgbuild_1.2.0           shape_1.4.5              Rmpfr_0.8-4              abind_1.4-5             
 [46] scales_1.1.1             mvtnorm_1.1-1            DBI_1.1.1                Rcpp_1.0.6               viridisLite_0.4.0       
 [51] tmvnsim_1.0-2            units_0.7-1              bit_4.0.4                proxy_0.4-25             stats4_4.1.0            
 [56] glmnet_4.1-1             CVXR_1.0-9               htmlwidgets_1.5.3        httr_1.4.2               RColorBrewer_1.1-2      
 [61] ellipsis_0.3.2           pkgconfig_2.0.3          farver_2.1.0             sass_0.3.1               dbplyr_2.1.1            
 [66] utf8_1.2.1               tidyselect_1.1.0         labeling_0.4.2           rlang_0.4.11             reshape2_1.4.4          
 [71] munsell_0.5.0            cellranger_1.1.0         tools_4.1.0              cachem_1.0.4             cli_2.5.0               
 [76] generics_0.1.0           devtools_2.4.2           broom_0.7.6              evaluate_0.14            fastmap_1.1.0           
 [81] yaml_2.2.1               processx_3.5.1           bit64_4.0.5              fs_1.5.0                 satellite_1.0.2         
 [86] xml2_1.3.2               compiler_4.1.0           rstudioapi_0.13          plotly_4.9.3             png_0.1-7               
 [91] e1071_1.7-6              bslib_0.2.4              stringi_1.5.3            highr_0.9                ps_1.6.0                
 [96] desc_1.3.0               lattice_0.20-44          Matrix_1.3-4             styler_1.4.1             classInt_0.4-3          
[101] vctrs_0.3.8              pillar_1.6.1             lifecycle_1.0.0          jquerylib_0.1.4          data.table_1.14.0       
[106] raster_3.4-5             mapview_2.9.0            R6_2.5.0                 gridExtra_2.3            KernSmooth_2.23-20      
[111] sessioninfo_1.1.1        codetools_0.2-18         MASS_7.3-53.1            assertthat_0.2.1         pkgload_1.2.1           
[116] rprojroot_2.0.2          withr_2.4.2              mnormt_2.0.2             hms_1.0.0                grid_4.1.0              
[121] class_7.3-19             rmarkdown_2.9            sf_0.9-8                 numDeriv_2016.8-1.1      lubridate_1.7.10        
[126] base64enc_0.1-3          ellipse_0.4.2    

sangwon-hyun avatar Sep 10 '21 07:09 sangwon-hyun

Thanks for sharing the code and figure! I appreciate it.

I agree that the default behavior should probably be different. I had some trouble implementing variable point size in ggrepel, so I hope this won't be too difficult.

Pull requests are welcome.

slowkow avatar Sep 10 '21 13:09 slowkow