slowkow / ggrepel

:round_pushpin: Repel overlapping text labels away from each other in your ggplot2 figures.
https://ggrepel.slowkow.com
GNU General Public License v3.0
1.22k stars 96 forks source link

Repel from segments created by geom_text_repel() #212

Closed brunomioto closed 2 years ago

brunomioto commented 2 years ago

Summary

There's a way to force geom_text_repel() to repel from segments created by the function? In my case, the text is repelling fine from the geom_line, but the line is crossing the text...

Here is an image:

Here in this example, 286 line clearly could be placed between 281 and 287 image

Version information

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

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

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

other attached packages:
 [1] extrafont_0.17  ggrepel_0.9.1   forcats_0.5.1   stringr_1.4.0   dplyr_1.0.7     purrr_0.3.4    
 [7] readr_2.0.2     tidyr_1.1.4     tibble_3.1.5    ggplot2_3.3.5   tidyverse_1.3.1

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1  haven_2.4.3       colorspace_2.0-2  vctrs_0.3.8       generics_0.1.1   
 [6] utf8_1.2.2        rlang_0.4.12      pillar_1.6.4      glue_1.4.2        withr_2.4.2      
[11] DBI_1.1.1         dbplyr_2.1.1      modelr_0.1.8      readxl_1.3.1      lifecycle_1.0.1  
[16] munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  ragg_1.2.0        rvest_1.0.2      
[21] tzdb_0.1.2        fansi_0.5.0       Rttf2pt1_1.3.9    broom_0.7.9       Rcpp_1.0.7       
[26] scales_1.1.1      backports_1.3.0   jsonlite_1.7.2    farver_2.1.0      fs_1.5.0         
[31] systemfonts_1.0.3 textshaping_0.3.6 hms_1.1.1         digest_0.6.28     stringi_1.7.5    
[36] grid_4.1.1        cli_3.0.1         tools_4.1.1       magrittr_2.0.1    crayon_1.4.1     
[41] extrafontdb_1.0   pkgconfig_2.0.3   ellipsis_0.3.2    xml2_1.3.2        reprex_2.0.1     
[46] lubridate_1.8.0   assertthat_0.2.1  httr_1.4.2        rstudioapi_0.13   R6_2.5.1         
[51] compiler_4.1.1   
slowkow commented 2 years ago

Thanks for the reprex!

This seems related to #110

I'm willing to review a pull request that implements this feature, but I do not plan to implement this myself.