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

Parsed labels breaks (bad anchoring) with phantom-dodging 0-length characters #126

Closed
yngman opened this issue Jan 17, 2019 · 2 comments
Closed

Comments

@yngman
Copy link

yngman commented Jan 17, 2019

Summary

In #49 (labels should not overlap unlabeled data points) fixed overlapping issue (for default parsed = FALSE), with 0-length characters denoting phantom labels.

However parsed = TRUE seem to break, causing labels to associate with the wrong data points.

Minimal code example

Code similar to #49, demonstrating expected output and that issue only appears with 0-length characters:

library(ggplot2)
library(dplyr)
library(tidyr)
library(ggrepel)

best <- mpg %>%
    group_by(class) %>%
    filter(hwy == max(hwy)) %>%
    distinct(model, .keep_all = T) %>% 
    mutate(best = model)
data <- mpg %>%
    left_join(best) %>%
    replace_na(list(best = '')) %>%
    mutate(best = gsub(' +', ' ~ ', best)) %>% 
    mutate(best = gsub('(\\d+)', '\\1*', best))

ggplot(data, aes(displ, hwy)) +
    geom_point(aes(colour = class)) +
    geom_label_repel(
        mapping = aes(label = best)
    )

ggplot(data, aes(displ, hwy)) +
    geom_point(aes(colour = class)) +
    geom_label_repel(
        mapping = aes(label = best),
        parse = TRUE
    )

ggplot(data, aes(displ, hwy)) +
    geom_point(aes(colour = class)) +
    geom_label_repel(
        mapping = aes(label = best),
        data = filter(data, nchar(best) > 0),
        parse = TRUE
    )

First plot, showing expected output (via parse = FALSE):

plot1

Second plot, showing issues when parse = TRUE:

plot2

Third plot, showing that parse = TRUE produces no issues with separate data (no phantom-dodging):

plot3

Version information

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

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 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               LC_TIME=sv_SE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=sv_SE.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=sv_SE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=sv_SE.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] tidyr_0.8.1    bindrcpp_0.2.2 ggrepel_0.8.0  dplyr_0.7.7    ggplot2_3.0.0  colorout_1.2-0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.19     rstudioapi_0.8   bindr_0.1.1      magrittr_1.5     tidyselect_0.2.5 munsell_0.5.0    colorspace_1.3-2
 [8] R6_2.3.0         rlang_0.2.2      fansi_0.4.0      plyr_1.8.4       tools_3.4.4      grid_3.4.4       gtable_0.2.0    
[15] utf8_1.1.4       cli_1.0.1        withr_2.1.2      digest_0.6.18    lazyeval_0.2.1   assertthat_0.2.0 tibble_1.4.2    
[22] crayon_1.3.4     purrr_0.2.5      glue_1.3.0       labeling_0.3     compiler_3.4.4   pillar_1.3.0     scales_1.0.0    
[29] pkgconfig_2.0.2
@slowkow
Copy link
Owner

slowkow commented Jan 17, 2019

Duplicate of #114

@slowkow slowkow marked this as a duplicate of #114 Jan 17, 2019
@slowkow slowkow closed this as completed Jan 17, 2019
@yngman
Copy link
Author

yngman commented Jan 18, 2019

Ah, my mistake! Sorry for that.

Tried to find earlier issue, but was probably to focused on the phrasing of #49 to notice #114.

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

2 participants