Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upgeom_label_repel(..., point.padding = NA) throws error: "'x' argument must be a unit object" #104
Comments
|
Thanks for reporting this issue! Also, thank you so much for providing a runnable example!! It was a bug in my code, but it should be fixed now. Here's an example with the development version of ggrepel: library(ggplot2)
library(ggrepel)
library(dplyr)
t <- tibble(Env = rep(LETTERS[1:3], c(4,3,2)),
nRpl = c(4:1, 3:1, 2:1),
nGt = c(1, 2, 4, 50, 1, 2, 10, 5, 7))
t <- t %>% mutate(nRpl = as.factor(nRpl))
t <- t %>% group_by(Env) %>% mutate(lPos = cumsum(nGt)-nGt/2) # label positions
p <- ggplot(t, aes(x = Env, y = nGt, fill = nRpl)) + geom_col()
# Works
# p + geom_text_repel(aes(y = lPos, label = nRpl), point.padding = NA)
# Should work now!
p + geom_label_repel(aes(y = lPos, label = nRpl), point.padding = NA) |

Summary
geom_text_repel(..., point.padding = NA)can be used to avoid text being repelled by other data points. I need this feature because I want to use ggrepel to annotate inside a bar plot, so the text must not be repelled by the bars.However, if I use
geom_label_repelinstead in this way, the following error is produced:Since Issue #79 / PR #80 it is possible to use
Minimal code example
Here is the minimum amount of code neeeded to demonstrate the issue:
Here is an image of the output produced by the code:
However, this does not work with
geom_label_repel:Suggestions
It would be nice if
geom_label_repelcould also ignore other non-text geoms like is the case forgeom_text_repel, for example if there are contrast issues between text and underlying graphics.A similar topic was issue #79.
Version information
Here is the output from
sessionInfo()in my R session: