-
-
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
Text not repeled properly when setting limits #186
Comments
Thanks for opening the issue. Please consider sharing a reprex. |
library(ggplot2)
library(ggrepel)
library(ggthemes)
df = read.table("~/DEBUG/DEBUG/ggrepel/Debug_dataset.txt", sep = "\t", header = T, quote = "", stringsAsFactors = F)
Diffcutoff = 0.25
gridlimit = ceiling(max(abs(df$Y_VAL))) + 2
options(ggrepel.max.overlaps = Inf)
ggplot(df) +
geom_point(aes(x = X_VAL, y = Y_VAL), size = 1.2, color = "gray57") +
geom_point( data = subset(df, TYPE != 'None'), size = 1.2, aes(x = X_VAL, y = Y_VAL, color = TYPE)) +
coord_cartesian(xlim = c(-gridlimit,gridlimit), ylim = c(-gridlimit, gridlimit))+
# SEGMENTS DRAWING
geom_segment(aes(x = -Diffcutoff, xend = -Diffcutoff, y = Diffcutoff, yend = (gridlimit + 1)), colour = "gray37", linetype = 2) + # SEGMENT VERTICAL TOP LEFT
geom_segment(aes(x = Diffcutoff, xend = Diffcutoff, y = Diffcutoff, yend = (gridlimit + 1)), colour = "gray37", linetype = 2) + # SEGMENT VERTICAL TOP RIGHT
geom_segment(aes(x = -Diffcutoff, xend = -Diffcutoff, y = -(gridlimit + 1), yend = -Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT VERTICAL BOTTOM LEFT
geom_segment(aes(x = Diffcutoff, xend = Diffcutoff, y = -(gridlimit + 1), yend = -Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT VERTICAL BOTTOM RIGHT
geom_segment(aes(x = -Diffcutoff, xend = -(gridlimit + 1), y = Diffcutoff, yend = Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT HORIZONTAL TOP LEFT
geom_segment(aes(x = Diffcutoff, xend = (gridlimit + 1), y = Diffcutoff, yend = Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT HORIZONTAL TOP RIGHT
geom_segment(aes(x = -Diffcutoff, xend = -(gridlimit + 1), y = -Diffcutoff, yend = -Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT HORIZONTAL BOTTOM LEFT
geom_segment(aes(x = Diffcutoff, xend = (gridlimit + 1), y = -Diffcutoff, yend = -Diffcutoff), colour = "gray37", linetype = 2) + # SEGMENT HORIZONTAL BOTTOM RIGHT
geom_text_repel(aes(fontface = 2, label = NAME, y = Y_VAL, x = X_VAL),
data = head(subset(df, TYPE == 'DOWNRIGHT'), 10),
segment.color = 'grey50',
segment.size = 0.2,
size = 2.8,
point.padding = 0.3,
force = 5,
xlim = c( Diffcutoff + 0.2, NA),
ylim = c(NA, -Diffcutoff - 0.2))
theme_linedraw() +
theme( plot.title = element_text(size = 17, color = 'black', hjust = 0.5),
panel.background = element_rect(size = 1.5, color = "black", linetype = "solid"),
legend.position = "none",
axis.line.x = element_line(size = 0.5, color = 'black'),
axis.line.y = element_line(size = 0.5, color = 'black'),
axis.text = element_text(size = 16),
axis.title = element_text(size = 17))
#> List of 93
#> $ line :List of 6
#> ..$ colour : chr "black"
#> ..$ size : num 0.5
#> ..$ linetype : num 1
#> ..$ lineend : chr "butt"
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ rect :List of 5
#> ..$ fill : chr "white"
#> ..$ colour : chr "black"
#> ..$ size : num 0.5
#> ..$ linetype : num 1
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ text :List of 11
#> ..$ family : chr ""
#> ..$ face : chr "plain"
#> ..$ colour : chr "black"
#> ..$ size : num 11
#> ..$ hjust : num 0.5
#> ..$ vjust : num 0.5
#> ..$ angle : num 0
#> ..$ lineheight : num 0.9
#> ..$ margin : 'margin' num [1:4] 0points 0points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ title : NULL
#> $ aspect.ratio : NULL
#> $ axis.title :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : num 17
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.title.x :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 1
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 2.75points 0points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.title.x.top :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 0
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 2.75points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.title.x.bottom : NULL
#> $ axis.title.y :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 1
#> ..$ angle : num 90
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 2.75points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.title.y.left : NULL
#> $ axis.title.y.right :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 0
#> ..$ angle : num -90
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 0points 2.75points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.text :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : chr "black"
#> ..$ size : num 16
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.text.x :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 1
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 2.2points 0points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.text.x.top :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : num 0
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 2.2points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.text.x.bottom : NULL
#> $ axis.text.y :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : num 1
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 2.2points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.text.y.left : NULL
#> $ axis.text.y.right :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : num 0
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 0points 2.2points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ axis.ticks :List of 6
#> ..$ colour : chr "black"
#> ..$ size : 'rel' num 0.5
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ axis.ticks.x : NULL
#> $ axis.ticks.x.top : NULL
#> $ axis.ticks.x.bottom : NULL
#> $ axis.ticks.y : NULL
#> $ axis.ticks.y.left : NULL
#> $ axis.ticks.y.right : NULL
#> $ axis.ticks.length : 'simpleUnit' num 2.75points
#> ..- attr(*, "unit")= int 8
#> $ axis.ticks.length.x : NULL
#> $ axis.ticks.length.x.top : NULL
#> $ axis.ticks.length.x.bottom: NULL
#> $ axis.ticks.length.y : NULL
#> $ axis.ticks.length.y.left : NULL
#> $ axis.ticks.length.y.right : NULL
#> $ axis.line : list()
#> ..- attr(*, "class")= chr [1:2] "element_blank" "element"
#> $ axis.line.x :List of 6
#> ..$ colour : chr "black"
#> ..$ size : num 0.5
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ axis.line.x.top : NULL
#> $ axis.line.x.bottom : NULL
#> $ axis.line.y :List of 6
#> ..$ colour : chr "black"
#> ..$ size : num 0.5
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ axis.line.y.left : NULL
#> $ axis.line.y.right : NULL
#> $ legend.background :List of 5
#> ..$ fill : NULL
#> ..$ colour : logi NA
#> ..$ size : NULL
#> ..$ linetype : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ legend.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
#> ..- attr(*, "unit")= int 8
#> $ legend.spacing : 'simpleUnit' num 11points
#> ..- attr(*, "unit")= int 8
#> $ legend.spacing.x : NULL
#> $ legend.spacing.y : NULL
#> $ legend.key :List of 5
#> ..$ fill : chr "white"
#> ..$ colour : logi NA
#> ..$ size : NULL
#> ..$ linetype : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ legend.key.size : 'simpleUnit' num 1.2lines
#> ..- attr(*, "unit")= int 3
#> $ legend.key.height : NULL
#> $ legend.key.width : NULL
#> $ legend.text :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : 'rel' num 0.8
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ legend.text.align : NULL
#> $ legend.title :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : num 0
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ legend.title.align : NULL
#> $ legend.position : chr "none"
#> $ legend.direction : NULL
#> $ legend.justification : chr "center"
#> $ legend.box : NULL
#> $ legend.box.just : NULL
#> $ legend.box.margin : 'margin' num [1:4] 0cm 0cm 0cm 0cm
#> ..- attr(*, "unit")= int 1
#> $ legend.box.background : list()
#> ..- attr(*, "class")= chr [1:2] "element_blank" "element"
#> $ legend.box.spacing : 'simpleUnit' num 11points
#> ..- attr(*, "unit")= int 8
#> $ panel.background :List of 5
#> ..$ fill : chr "white"
#> ..$ colour : chr "black"
#> ..$ size : num 1.5
#> ..$ linetype : chr "solid"
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ panel.border :List of 5
#> ..$ fill : logi NA
#> ..$ colour : chr "black"
#> ..$ size : 'rel' num 1
#> ..$ linetype : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ panel.spacing : 'simpleUnit' num 5.5points
#> ..- attr(*, "unit")= int 8
#> $ panel.spacing.x : NULL
#> $ panel.spacing.y : NULL
#> $ panel.grid :List of 6
#> ..$ colour : chr "black"
#> ..$ size : NULL
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ panel.grid.major :List of 6
#> ..$ colour : NULL
#> ..$ size : 'rel' num 0.1
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ panel.grid.minor :List of 6
#> ..$ colour : NULL
#> ..$ size : 'rel' num 0.05
#> ..$ linetype : NULL
#> ..$ lineend : NULL
#> ..$ arrow : logi FALSE
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_line" "element"
#> $ panel.grid.major.x : NULL
#> $ panel.grid.major.y : NULL
#> $ panel.grid.minor.x : NULL
#> $ panel.grid.minor.y : NULL
#> $ panel.ontop : logi FALSE
#> $ plot.background :List of 5
#> ..$ fill : NULL
#> ..$ colour : chr "white"
#> ..$ size : NULL
#> ..$ linetype : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ plot.title :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : chr "black"
#> ..$ size : num 17
#> ..$ hjust : num 0.5
#> ..$ vjust : num 1
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi FALSE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ plot.title.position : chr "panel"
#> $ plot.subtitle :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : num 0
#> ..$ vjust : num 1
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 0points 0points 5.5points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ plot.caption :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : 'rel' num 0.8
#> ..$ hjust : num 1
#> ..$ vjust : num 1
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 5.5points 0points 0points 0points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ plot.caption.position : chr "panel"
#> $ plot.tag :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : 'rel' num 1.2
#> ..$ hjust : num 0.5
#> ..$ vjust : num 0.5
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ plot.tag.position : chr "topleft"
#> $ plot.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
#> ..- attr(*, "unit")= int 8
#> $ strip.background :List of 5
#> ..$ fill : chr "black"
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ linetype : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_rect" "element"
#> $ strip.background.x : NULL
#> $ strip.background.y : NULL
#> $ strip.placement : chr "inside"
#> $ strip.text :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : chr "white"
#> ..$ size : 'rel' num 0.8
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : NULL
#> ..$ lineheight : NULL
#> ..$ margin : 'margin' num [1:4] 4.4points 4.4points 4.4points 4.4points
#> .. ..- attr(*, "unit")= int 8
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ strip.text.x : NULL
#> $ strip.text.y :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : num -90
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> $ strip.switch.pad.grid : 'simpleUnit' num 2.75points
#> ..- attr(*, "unit")= int 8
#> $ strip.switch.pad.wrap : 'simpleUnit' num 2.75points
#> ..- attr(*, "unit")= int 8
#> $ strip.text.y.left :List of 11
#> ..$ family : NULL
#> ..$ face : NULL
#> ..$ colour : NULL
#> ..$ size : NULL
#> ..$ hjust : NULL
#> ..$ vjust : NULL
#> ..$ angle : num 90
#> ..$ lineheight : NULL
#> ..$ margin : NULL
#> ..$ debug : NULL
#> ..$ inherit.blank: logi TRUE
#> ..- attr(*, "class")= chr [1:2] "element_text" "element"
#> - attr(*, "class")= chr [1:2] "theme" "gg"
#> - attr(*, "complete")= logi TRUE
#> - attr(*, "validate")= logi TRUE Created on 2021-02-25 by the reprex package (v1.0.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Hello,
I'm trying to repel labels at each corner of my graph using xlim and ylim.
However, repeled texts still overlap within those areas.
The exemple here only stands for bottom right names for simplicity.
Minimal code example
A head of my dataframe looks like this...
... and here's the code for plotting
Here is an image of the output produced by the code:
Suggestions
Unfortunately not but any help would be greatly appreciated ;-)
Version information
Here is the output from
sessionInfo()
in my R session:The text was updated successfully, but these errors were encountered: