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

Labels do not appear in version 0.9.5 #261

Closed arodionoff closed 5 months ago

arodionoff commented 5 months ago

Summary

Behaviour difference between new vs. old version of your package. The labels are produced with ‘ggrepel’ version 0.9.4, but not with version 0.9.5 on Windows & Ubuntu (I do not have any Mac computer).

Minimal code example

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

install.packages('apyramid')
library('apyramid')         # Visualize Population Pyramids Aggregated by Age
data(us_2018)
df <- us_2018
df$count <- ifelse(df$gender == 'male', -df$count, df$count)
apyramid::age_pyramid(us_2018, age_group = "age", split_by = "gender", count= 'count') +
    ggrepel::geom_text_repel(data = df, ggplot2::aes(x = age, y = count, label = paste0(percent, '%')), size = 5)

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

изображение

изображение

Suggestions

Eliminate the reasons for the lack of text output in the new version of the package.

Version information

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

**R version 4.4.0 (2024-04-24)**
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so;  LAPACK version 3.9.0

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

time zone: UTC
tzcode source: system (glibc)

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

other attached packages:
[1] apyramid_0.1.3

loaded via a namespace (and not attached):
 [1] RColorBrewer_1.1-3 utf8_1.2.4         R6_2.5.1           tidyselect_1.2.1   farver_2.1.2       magrittr_2.0.3    
 [7] gtable_0.3.5       glue_1.7.0         tibble_3.2.1       pkgconfig_2.0.3    generics_0.1.3     dplyr_1.1.4       
[13] lifecycle_1.0.4    ggplot2_3.5.1      cli_3.6.2          fansi_1.0.6        scales_1.3.0       grid_4.4.0        
[19] vctrs_0.6.5        withr_3.0.0        compiler_4.4.0     tools_4.4.0        munsell_0.5.1      pillar_1.9.0      
[25] Rcpp_1.0.12        colorspace_2.1-0   rlang_1.1.3        **ggrepel_0.9.5**
mschubert commented 5 months ago

I'm facing the same issue. geom_label works as expected, but geom_label_repel shows no labels in 0.9.5. 0.9.4 works as well, 0.9.5.9999 does not.

slowkow commented 5 months ago

This issue is related to: #253 #255 #257 #260

Commit 4119c28957e956ad39d65254a4ce76377ed0e5ae should fix it.

library(apyramid)
library(ggrepel)
#> Loading required package: ggplot2

data(us_2018)
df <- us_2018
df$count <- ifelse(df$gender == 'male', -df$count, df$count)

# using ggrepel::geom_text_repel()
age_pyramid(us_2018, age_group = "age", split_by = "gender", count= 'count') +
  geom_text_repel(
    data = df,
    mapping = aes(x = age, y = count, label = paste0(percent, '%')),
    size = 5,
    position = position_nudge_repel(y = ifelse(df$gender == "female", 100, -100))
  ) +
  scale_y_continuous(expand = expansion(mult = 0.2))
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.


# using ggplot2::geom_text()
age_pyramid(us_2018, age_group = "age", split_by = "gender", count= 'count') +
  geom_text(
    data = df,
    mapping = aes(x = age, y = count, label = paste0(percent, '%')),
    size = 5,
    position = position_nudge(y = 3e3 * ifelse(df$gender == "female", 1, -1))
  ) +
  scale_y_continuous(expand = expansion(mult = 0.2))
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

Created on 2024-05-16 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.3 (2023-03-15) #> os macOS Ventura 13.4 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2024-05-16 #> pandoc 3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> apyramid * 0.1.3 2023-02-14 [1] CRAN (R 4.2.0) #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.2.3) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.2.0) #> curl 5.2.1 2024-03-01 [1] CRAN (R 4.2.3) #> digest 0.6.31 2022-12-11 [1] CRAN (R 4.2.0) #> dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.2.3) #> evaluate 0.21 2023-05-05 [1] CRAN (R 4.2.0) #> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.2.3) #> farver 2.1.1 2022-07-06 [1] CRAN (R 4.2.0) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.0) #> fs 1.6.2 2023-04-25 [1] CRAN (R 4.2.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.0) #> ggplot2 * 3.5.1 2024-04-23 [1] CRAN (R 4.2.3) #> ggrepel * 0.9.5.9999 2024-05-16 [1] local #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.2.3) #> gtable 0.3.4 2023-08-21 [1] CRAN (R 4.2.0) #> highr 0.10 2022-12-22 [1] CRAN (R 4.2.0) #> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.2.0) #> knitr 1.43 2023-05-25 [1] CRAN (R 4.2.0) #> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.2.0) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.2.3) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.2.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.2.3) #> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.2.3) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.2.0) #> Rcpp 1.0.11 2023-07-06 [1] CRAN (R 4.2.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.0) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.2.3) #> rmarkdown 2.23 2023-07-01 [1] CRAN (R 4.2.0) #> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.2.0) #> scales 1.3.0 2023-11-28 [1] CRAN (R 4.2.3) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> styler 1.10.2 2023-08-29 [1] CRAN (R 4.2.0) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.2.0) #> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.2.3) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.2.0) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.2.3) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.2.3) #> xfun 0.39 2023-04-20 [1] CRAN (R 4.2.0) #> xml2 1.3.4 2023-04-27 [1] CRAN (R 4.2.0) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```