-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Justification bug in geom_text_repel() #210
Comments
I think this might fix the issue: All examples in the documentation website seem to be OK after this commit. And I checked a few of your examples, and they seem to be OK. (See below for details.) library(ggplot2)
#library(ggnetwork)
library(ggrepel)
finalxy2 <- structure(list(
xpos = c(-2, 0, 0, 6, 2, 6, 4, 6, 2, -6, -4, 0,
4, 0, 8, 8, -4, -2, -2, 8, 10, 2, 0, -4, -2, 4)
, ypos = c(4, 2, 4, 4, 0, 2, -2, -2, 2, -2, -2, 0, -4, -2, -4, -2, 0, 0, -2,
0, 0, -2, -4, -4, -4, 4)
, vertex.names = paste("name",1:26) )
, row.names = c(NA, -26L)
, class = "data.frame")
# the output is wrong (but not for geom_label_repel(), not shown)
ggplot(finalxy2) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 0.5,
fontface = "italic", size=2, max.iter = 0
) + expand_limits(y = c(-5, 5), x = c(-7, 12)) ggplot(finalxy2) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 1,
fontface = "italic", size=2, max.iter = 0
) + expand_limits(y = c(-5, 5), x = c(-7, 12)) # here the output is also wrong
ggplot(finalxy2) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0.5,
fontface = "italic", size=2, max.iter = 0
) + expand_limits(y = c(-5, 5), x = c(-7, 12)) # but here the output is correct
ggplot(finalxy2) +
# geom_edges(data=posData1, aes(x = xorig, y = yorig, xend = xtarg, yend = ytarg),
# arrow = arrow(length = unit(5, "pt"), type = "closed")
# ) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0,
fontface = "italic", size=2, max.iter = 0
) + expand_limits(y = c(-5, 5), x = c(-7, 12)) library(ggrepel)
#> Loading required package: ggplot2
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
d <- data.frame(x = 1, y = 1, label = "this\nis a\nlong label")
ggplot(d, aes(x, y, label = label)) +
geom_text(hjust = 0) ggplot(d, aes(x, y, label = label)) +
geom_text_repel(hjust = 0) library(ggrepel)
#> Loading required package: ggplot2
set.seed(42)
p <- ggplot(mtcars, aes(y = wt, x = 1, label = rownames(mtcars))) +
geom_point(color = "red") +
ylim(1, 5.5) +
theme(
axis.line.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.title.x = element_blank()
)
p +
xlim(1, 1.375) +
geom_text_repel(
force = 0.5,
nudge_x = 0.15,
direction = "y",
hjust = 0,
segment.size = 0.2
) +
ggtitle("hjust = 0") Created on 2021-11-07 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.3 (2020-10-10)
#> os macOS Catalina 10.15.7
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2021-11-07
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.2)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.2)
#> cli 3.0.1 2021-07-17 [1] CRAN (R 4.0.2)
#> colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.0.2)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.0.2)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.2)
#> digest 0.6.28 2021-09-23 [1] CRAN (R 4.0.2)
#> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.1)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.0.2)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.0.2)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.2)
#> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.0.2)
#> ggrepel * 0.9.1.9999 2021-11-08 [1] local
#> glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.2)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.2)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [2] CRAN (R 4.0.2)
#> knitr 1.36 2021-09-29 [1] CRAN (R 4.0.2)
#> labeling 0.4.2 2020-10-20 [2] CRAN (R 4.0.2)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1.9000 2020-12-15 [1] Github (tidyverse/magrittr@bb1c86a)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.2)
#> pillar 1.6.3 2021-09-26 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.2)
#> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.0.2)
#> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.0.2)
#> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.0.2)
#> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.0.2)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.0.2)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.0.2)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.0.2)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.2)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.0.2)
#> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.2)
#> stringi 1.7.5 2021-10-04 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.2)
#> styler 1.6.2 2021-09-23 [1] CRAN (R 4.0.2)
#> tibble 3.1.5 2021-09-30 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.0.2)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.0.2)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.2)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.2)
#> xfun 0.26 2021-09-14 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [2] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.2)
#>
#> [1] /Users/kamil/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library |
@slowkow The commit solves the examples in my previous reprex, but further testing shows that some other combinations of I composed pairs of plots to make it easier to see the differences between ## reprex for bug remaining after commit by Slokow
library(ggplot2)
library(patchwork)
library(ggrepel)
finalxy2 <- structure(list(
xpos = c(-2, 0, 0, 6, 2, 6, 4, 6, 2, -6, -4, 0,
4, 0, 8, 8, -4, -2, -2, 8, 10, 2, 0, -4, -2, 4)
, ypos = c(4, 2, 4, 4, 0, 2, -2, -2, 2, -2, -2, 0, -4, -2, -4, -2, 0, 0, -2,
0, 0, -2, -4, -4, -4, 4)
, vertex.names = paste("name",1:26) )
, row.names = c(NA, -26L)
, class = "data.frame")
p <- ggplot(finalxy2) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
expand_limits(y = c(-5, 5), x = c(-7, 12))
## interaction between vjust and hjust is not yet correct in several cases
# "inward" examples
# here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "inward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "inward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "inward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "inward",
hjust = "inward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "inward",
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # "outward"
# here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "outward",
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "outward",
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 1,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 1,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 0,
fontface = "italic", size = 3) +
ggtitle("text")) Created on 2021-11-08 by the reprex package (v2.0.1) |
@aphalo Thank you so much for sharing these examples! I think this might be a good test suite for |
@slowkow You are welcome! These examples are still missing the test for angle different to zero... I made quite a lot of progress in the last few hours, including writing a few examples for other angles. The problem was indeed in the lines you edited but the edit did not solve the problem as shown above. It is now fixed for angles of zero degrees and multiples of 180 degrees. For other angles justification is too much. I will continue working on this possibly tomorrow. I find the values for |
@aphalo Oh boy, the You're right that we need more tests for various angles ... but it is not an easy task to get this working. Your examples are a good start, at least. Thank you for giving it a shot! |
@slowkow Solving the "justification with angle" bug in 'ggplot2' was quite involved to work out as the justification is relative to the orientation of the text, instead of the plot. I want to try to get this also working in 'ggrepel' before I forget the logic behind these manipulations... |
Here are the same examples as above plus new ones as a reprex run with the code at commit 76d8ff4 library(ggplot2)
library(patchwork)
library(ggrepel)
finalxy2 <- structure(list(
xpos = c(-2, 0, 0, 6, 2, 6, 4, 6, 2, -6, -4, 0,
4, 0, 8, 8, -4, -2, -2, 8, 10, 2, 0, -4, -2, 4)
, ypos = c(4, 2, 4, 4, 0, 2, -2, -2, 2, -2, -2, 0, -4, -2, -4, -2, 0, 0, -2,
0, 0, -2, -4, -4, -4, 4)
, vertex.names = paste("name",1:26) )
, row.names = c(NA, -26L)
, class = "data.frame")
p <- ggplot(finalxy2) +
geom_point(aes(x=xpos, y=ypos ), size = 2) +
expand_limits(y = c(-5, 5), x = c(-7, 12))
## interaction between vjust and hjust is not yet correct in several cases
# "inward" examples
# here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "inward",
box.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "inward",
box.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "inward",
box.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "inward",
hjust = "inward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "inward",
hjust = "inward",
fontface = "italic", size = 3) +
ggtitle("text")) # "outward"
# here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "outward",
hjust = "outward",
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = "outward",
hjust = "outward",
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 1,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 1,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 0,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
angle = 90,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
angle = 90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
angle = -90,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0.5,
hjust = 0.5,
angle = -90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = 90,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = 90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 90,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = -90,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = -90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -90,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -90,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = 45,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 1,
hjust = 1,
angle = 45,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 45,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 45,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 180,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 180,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is wrong both vertically and horizontally
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 45,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 10000) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 45,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 180,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 10000) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = 180,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -10,
box.padding = 0,
point.padding = 0,
fontface = "italic", size = 3, max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -10,
fontface = "italic", size = 3) +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -250,
box.padding = 0,
point.padding = 0,
fontface = "italic", max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos, label = vertex.names),
vjust = 0,
hjust = 0,
angle = -250,
fontface = "italic") +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos), label = "A",
size = 6,
vjust = 0,
hjust = 0,
angle = -250,
box.padding = 0,
point.padding = 0,
fontface = "italic", max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos), label = "A",
size = 6,
vjust = 0,
hjust = 0,
angle = -250,
fontface = "italic") +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 6,
vjust = 0,
hjust = 0,
angle = -250,
box.padding = 0,
point.padding = 0,
fontface = "italic", max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 6,
vjust = 0,
hjust = 0,
angle = -250,
fontface = "italic") +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 6,
vjust = 0,
hjust = 0,
angle = 0,
box.padding = 0,
point.padding = 0,
fontface = "italic", max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 6,
vjust = 0,
hjust = 0,
angle = 0,
fontface = "italic") +
ggtitle("text")) # here the justification is correct
(p +
geom_text_repel(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 2,
vjust = 0,
hjust = 0,
angle = 90,
box.padding = 0,
point.padding = 0,
fontface = "italic", max.iter = 0) +
ggtitle("text_repel")) /
(p +
geom_text(aes(x=xpos, y=ypos), label = "A\nB\nC",
size = 2,
vjust = 0,
hjust = 0,
angle = 90,
fontface = "italic") +
ggtitle("text")) Created on 2021-11-11 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> - Session info --------------------------------------------------------------
#> hash: handshake, rose, baby angel: 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-11
#> 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)
#> patchwork * 1.1.1 2020-12-17 [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
#>
#> ------------------------------------------------------------------------------ |
👏👏👏👏👏 Fantastic examples! Thank you so much for the reprex and all the detective work. Most cases look pretty good. After reading some of your messages and pull requests, I wonder if we should change all of the code in ggrepel to use a different unit than "npc"? Maybe "points"? I have not tested how different units work, and I wonder if maybe this is related to the discrepancy between ggrepel and ggplot2? The example with "A\nB\nC" is interesting, but I don't know how to fix it. |
I am closing this issue, but will add some selected examples from here as test cases to #196 |
Summary
The initial position before repulsion is wrong for some values of
hjust
. The reprex below is based on the reprex in #191, but while working on #191 I found this bug ingeom_text_repel()
which does not seem to affectgeom_label_repel()
in the same way. So, the bug reported in #191 seems to be a different one.Minimal code example
Here is the minimum amount of code needed to demonstrate the issue:
Created on 2021-11-05 by the reprex package (v2.0.1)
Session info
Suggestions
@slowkow I will try to find the culprit but you probably now the code where this is happening better than myself.
The text was updated successfully, but these errors were encountered: