Repository navigation
bizarre difference between locations of geom_text vs. geom_label? #182
Copy link
Copy link
Closed
Description
Summary
geom_label_repel() is placing labels in strange locations that are very far from the (correct) geom_text_repel() placements. This behavior appears to be new in v0.9.0.
Minimal code example
set.seed(23)
library(tidyverse)
library(alr3)
#> Loading required package: car
#> Loading required package: carData
#>
#> Attaching package: 'car'
#> The following object is masked from 'package:dplyr':
#>
#> recode
#> The following object is masked from 'package:purrr':
#>
#> some
challeng <- challeng %>%
mutate(
label = case_when(
Damage == 11 ~ "SRM 15",
Damage == 4 & Temp == 75 ~ "SRM 22",
TRUE ~ ""
)
)
challenger_plot <- ggplot(data = challeng, aes(x = Temp, y = Damage)) +
geom_jitter(size = 5, height = 0.25, width = 0.25, alpha = 0.5) +
geom_smooth()
challenger_plot + ggrepel::geom_text_repel(aes(label = label))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'challenger_plot + ggrepel::geom_label_repel(aes(label = label))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'sessionInfo()
#> R version 4.0.3 (2020-10-10)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.5 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] 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
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] alr3_2.0.8 car_3.0-10 carData_3.0-4 forcats_0.5.0
#> [5] stringr_1.4.0 dplyr_1.0.2 purrr_0.3.4 readr_1.4.0
#> [9] tidyr_1.1.2 tibble_3.0.4 ggplot2_3.3.3 tidyverse_1.3.0
#>
#> loaded via a namespace (and not attached):
#> [1] ggrepel_0.9.0 Rcpp_1.0.5 lattice_0.20-41 lubridate_1.7.9.2
#> [5] assertthat_0.2.1 digest_0.6.27 R6_2.5.0 cellranger_1.1.0
#> [9] backports_1.2.1 reprex_0.3.0 evaluate_0.14 httr_1.4.2
#> [13] highr_0.8 pillar_1.4.7 rlang_0.4.10 curl_4.3
#> [17] readxl_1.3.1 data.table_1.13.6 Matrix_1.3-0 rmarkdown_2.6
#> [21] labeling_0.4.2 splines_4.0.3 foreign_0.8-81 munsell_0.5.0
#> [25] broom_0.7.3 compiler_4.0.3 modelr_0.1.8 xfun_0.19
#> [29] pkgconfig_2.0.3 mgcv_1.8-33 htmltools_0.5.0 tidyselect_1.1.0
#> [33] rio_0.5.16 fansi_0.4.1 crayon_1.3.4 dbplyr_2.0.0
#> [37] withr_2.3.0 grid_4.0.3 nlme_3.1-151 jsonlite_1.7.2
#> [41] gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0 magrittr_2.0.1
#> [45] scales_1.1.1 zip_2.1.1 cli_2.2.0 stringi_1.5.3
#> [49] farver_2.0.3 fs_1.5.0 xml2_1.3.2 ellipsis_0.3.1
#> [53] generics_0.1.0 vctrs_0.3.6 openxlsx_4.2.3 tools_4.0.3
#> [57] glue_1.4.2 hms_0.5.3 abind_1.4-5 yaml_2.2.1
#> [61] colorspace_2.0-0 rvest_0.3.6 knitr_1.30 haven_2.3.1Created on 2021-01-09 by the reprex package (v0.3.0)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels


Activity
beanumber commentedon Jan 9, 2021
FYI, adding
data = filter(challeng, label > "")fixes the problem.So I solved my immediate problem, but it still seems weird that the two functions behave differently. I'm leaving this open in case you want to pursue it further.
slowkow commentedon Jan 9, 2021
Thanks for reporting the issue! I appreciate it.
I can't run your code, because I don't have your data.
Please consider sharing an example that I can run on my own computer.
Here's what I see:
Created on 2021-01-09 by the reprex package (v0.3.0)
Session info
slowkow commentedon Jan 9, 2021
slowkow commentedon Jan 9, 2021
Hm... I think I might be seeing the same strange behavior you reported. It's difficult to make a reproducible example, though!
slowkow commentedon Jan 9, 2021
I just pushed 8adf073
While I can't make an example that looks similar to yours, I did notice that this commit seemed to change the way
geom_label_repel()positions the labels. Maybe this fixed it? I don't know.Could I please ask you to try running your example again with this the GitHub version of ggrepel?
Thanks again for your report! I don't usually use
geom_label_repel(), and I rely on the examples to make sure that the code is working, but I guess I probably need more tests.beanumber commentedon Jan 9, 2021
FYI: https://cran.r-project.org/src/contrib/Archive/alr3/
beanumber commentedon Jan 9, 2021
Thanks for the quick response!
I still see the problem persisting in the patch you mentioned.
I can also confirm that the behavior does NOT occur in v0.8.2.
It looks like
alr3was pulled from CRAN, but you can get an archived version at the link above if you want to verify the bug.slowkow commentedon Jan 9, 2021
I was able to reproduce your example after installing an old version of
alr3.Thanks again. I'll let you know when I figure out what is going on...
slowkow commentedon Jan 9, 2021
@beanumber I found a bug and fixed it! Thank you so much. That was an important bug, so I plan to push a fix to CRAN soon.
beanumber commentedon Jan 9, 2021
Glad to be of service. Thanks for everything you've put into this!
fix slowkow#182