-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
Segment not reaching the label box when using hjust #171
Comments
Weird! Thank you for reporting this. I never noticed this before, and I think it is a bug. |
What looks like a similar problem affecting justification can be seen in some of the examples of the new position nudge functions. |
@slowkow This problem seems to be related to an interaction between justification and box padding. It still exists in the code in pull request #196 as of commit 76d8ff4 library(ggplot2)
library(ggrepel)
# Set graph output dimension for reproducibility purposes
#dev.new(width = 6, height = 12, unit = "in")
ggplot() +
geom_label_repel(
aes(x = c(1, 1.1),
y = c(1, 1.1)
),
label = "testing for segment\nelongation",
fill = NA,
min.segment.length = 0,
hjust = 1
) +
xlim(c(1,100)) +
ylim(c(1,100)) ggplot() +
geom_label_repel(
aes(x = c(1, 1.1),
y = c(1, 1.1)
),
label = "testing for segment\nelongation",
fill = NA,
min.segment.length = 0,
hjust = 1,
box.padding = 1
) +
xlim(c(1,100)) +
ylim(c(1,100)) ggplot() +
geom_label_repel(
aes(x = c(1, 1.1),
y = c(1, 1.1)
),
label = "testing for segment\nelongation",
fill = NA,
min.segment.length = 0,
hjust = 1,
box.padding = 0
) +
xlim(c(1,100)) +
ylim(c(1,100)) Created on 2021-11-10 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> - Session info --------------------------------------------------------------
#> hash: sad but relieved face, man: medium-dark skin tone, person facepalming: medium-light skin tone
#>
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os Windows 10 x64 (build 19043)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_Finland.1252
#> ctype English_Finland.1252
#> tz Europe/Helsinki
#> date 2021-11-10
#> pandoc 2.14.0.3 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#>
#> - Packages -------------------------------------------------------------------
#> package * version date (UTC) lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
#> backports 1.3.0 2021-10-27 [1] CRAN (R 4.1.1)
#> cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.1)
#> colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.0)
#> crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.1)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
#> digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.1)
#> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
#> generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.1)
#> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.0)
#> ggrepel * 0.9.1.9999 2021-11-10 [1] local
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.1)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0)
#> knitr 1.36 2021-09-29 [1] CRAN (R 4.1.1)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.1.1)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0)
#> pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.1)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
#> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.0)
#> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.0)
#> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.0)
#> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.1)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.1)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0)
#> sessioninfo 1.2.1 2021-11-02 [1] CRAN (R 4.1.1)
#> stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
#> styler 1.6.2 2021-09-23 [1] CRAN (R 4.1.1)
#> tibble 3.1.5 2021-09-30 [1] CRAN (R 4.1.1)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
#> xfun 0.27 2021-10-18 [1] CRAN (R 4.1.1)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
#>
#> [1] C:/Users/Aphalo/Documents/R/win-library/4.1
#> [2] C:/Program Files/R/R-4.1.1/library
#>
#> ------------------------------------------------------------------------------ |
Summary
When using
hjust
option to justify text, segment line does not reach the label box. Issue is not always reproducible, depends on the size of the image and the position of the label boxes.Issue is very apparent when using labels with maps (
geom_sf()
)Minimal code example
Here is an image of the output produced by the code:
As you can see from the screenshot, the lower box segment is not reaching the box.
Removing hjust option renders the segment correctly
Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: