slowkow/ggrepel

Overlap of labels on edge with hjust/vjust

Open

#95 opened on Dec 25, 2017

View on GitHub
 (0 comments) (0 reactions) (0 assignees)R (1,257 stars) (95 forks)batch import
bughelp wanted

Description

Summary

When setting hjust to a value outside 0..1 range, in cases it would push text over the plotting area edge, text overlaps point. The problem can be reproduced only at certain plotting area sizes, rather small ones in most cases. (Anyway, it seems like setting hjust reduces repulsive force in the y direction.)

(@slowkow @AliciaSchep While adding visual test cases I noticed some problems, this is one of them.)

Minimal code example

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

  dat <- subset(mtcars, wt > 2.75 & wt < 3.45)
  dat$car <- rownames(dat)
  set.seed(42)

  p <- ggplot(dat, aes(wt, mpg, label = car)) +
    geom_point()

Problem on right edge.

p + geom_text_repel(hjust = -0.5)

Problem on bottom edge.

p + geom_text_repel(vjust = 1.5, angle = 90)

Problem on left edge.

p + geom_text_repel(hjust = 1.5)

Here is an image of the output produced by the code immediately above. Rstudio not at full screen: rplot

RStudio full screen (redrawn automatically after switch to full screen): rplot01

Suggestions

None, as I haven't studied the repulsion code.

Version information

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

Session info ------------------------------------------------------------------------------------------------------------------
 setting  value                                      
 version  R version 3.4.3 Patched (2017-12-14 r73916)
 system   x86_64, mingw32                            
 ui       RStudio (1.1.402)                          
 language (EN)                                       
 collate  English_United Kingdom.1252                
 tz       Europe/Helsinki                            
 date     2017-12-25                                 

Packages ----------------------------------------------------------------------------------------------------------------------
 package    * version    date       source                            
 base       * 3.4.3      2017-12-15 local                             
 colorspace   1.3-2      2016-12-14 CRAN (R 3.4.0)                    
 compiler     3.4.3      2017-12-15 local                             
 datasets   * 3.4.3      2017-12-15 local                             
 devtools   * 1.13.4     2017-11-09 CRAN (R 3.4.2)                    
 digest       0.6.13     2017-12-14 CRAN (R 3.4.3)                    
 ggplot2    * 2.2.1.9000 2017-12-24 Github (tidyverse/ggplot2@a637c67)
 ggrepel    * 0.7.2      2017-12-25 Github (slowkow/ggrepel@ab51ed2)  
 graphics   * 3.4.3      2017-12-15 local                             
 grDevices  * 3.4.3      2017-12-15 local                             
 grid         3.4.3      2017-12-15 local                             
 gtable       0.2.0      2016-02-26 CRAN (R 3.4.0)                    
 labeling     0.3        2014-08-23 CRAN (R 3.4.0)                    
 lazyeval     0.2.1      2017-10-29 CRAN (R 3.4.2)                    
 memoise      1.1.0      2017-04-21 CRAN (R 3.4.0)                    
 methods    * 3.4.3      2017-12-15 local                             
 munsell      0.4.3      2016-02-13 CRAN (R 3.4.0)                    
 plyr         1.8.4      2016-06-08 CRAN (R 3.4.0)                    
 Rcpp         0.12.14    2017-11-23 CRAN (R 3.4.2)                    
 rlang        0.1.4.9000 2017-12-16 Github (tidyverse/rlang@cc7587c)  
 rstudioapi   0.7        2017-09-07 CRAN (R 3.4.1)                    
 scales       0.5.0.9000 2017-09-01 Github (hadley/scales@d767915)    
 stats      * 3.4.3      2017-12-15 local                             
 tibble       1.3.4      2017-08-22 CRAN (R 3.4.1)                    
 tools        3.4.3      2017-12-15 local                             
 utils      * 3.4.3      2017-12-15 local                             
 withr        2.1.1.9000 2017-12-24 Github (jimhester/withr@df18523)  
 yaml         2.1.16     2017-12-12 CRAN (R 3.4.3)          ```

Contributor guide