Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texts created using geom_text_repel() in ggplot2 disappear when the plot is flipped using coord_flip(). #253

Open
nidoe44 opened this issue Jan 26, 2024 · 4 comments

Comments

@nidoe44
Copy link

nidoe44 commented Jan 26, 2024

Summary

Texts created using geom_text_repel() in ggplot2 disappear when the plot is flipped using coord_flip().

Minimal code example

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

ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg, label = rownames(mtcars))) +
    ggrepel::geom_text_repel() +
    ggplot2::geom_point(color = 'red') +
    ggplot2::theme_classic(base_size = 16) + 
    ggplot2::coord_flip()

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

image

Possible Workaround

Using prior version ggrepel_0.9.2

Version information

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

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10      ggrepel_0.9.5    fansi_1.0.4      withr_2.5.0      dplyr_1.1.1      utf8_1.2.3      
 [7] grid_4.2.3       R6_2.5.1         lifecycle_1.0.3  gtable_0.3.3     magrittr_2.0.3   scales_1.2.1    
[13] ggplot2_3.4.4    pillar_1.9.0     rlang_1.1.0      cli_3.6.1        farver_2.1.1     rstudioapi_0.14 
[19] generics_0.1.3   vctrs_0.6.1      labeling_0.4.2   tools_4.2.3      glue_1.6.2       munsell_0.5.0   
[25] compiler_4.2.3   pkgconfig_2.0.3  colorspace_2.1-0 tidyselect_1.2.0 tibble_3.2.1 
@slowkow
Copy link
Owner

slowkow commented Jan 26, 2024

Thanks for sharing the example code and figure!

I think this is probably due to the recent change to make ggrepel compatible with ggbreak (see here for more details).

I wonder if there is an easy fix... pull requests are very welcome.

@rrrrrhhhhh
Copy link

rrrrrhhhhh commented Feb 9, 2024

If it helps, I observed the same issue when applying a transformation to the coordinates. See example below:

library(ggrepel)
library(scales)
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_text_repel() +
geom_point(color = 'red') +
theme_classic(base_size = 16) +
coord_trans(y = pseudo_log_trans(base = 2, sigma = 0.1))

@slowkow
Copy link
Owner

slowkow commented Feb 9, 2024

Thanks @rrrrrhhhhh it's always helpful to have additional test cases.

I think I might need to revert the code back to an earlier version, and drop support for ggbreak. The coordinate transformation seems more important to me than compatibility with ggbreak.

@slowkow
Copy link
Owner

slowkow commented May 16, 2024

This issue should be fixed by this commit in the latest development version.

4119c28

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

# example 1
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
  geom_text_repel() +
  geom_point(color = 'red') +
  theme_classic(base_size = 16) +
  coord_flip()
#> Warning: ggrepel: 2 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

# example 2
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
  geom_text_repel() +
  geom_point(color = 'red') +
  theme_classic(base_size = 16)
p
#> Warning: ggrepel: 2 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

p + scale_x_continuous(limits = c(NA, 3))
#> Warning: Removed 20 rows containing missing values or values outside the scale range
#> (`geom_text_repel()`).
#> Warning: Removed 20 rows containing missing values or values outside the scale range
#> (`geom_point()`).

p + coord_trans(y = pseudo_log_trans(base = 2, sigma = 0.1))

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

Session info
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
#>  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)
#>  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
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants