As far as I can see ggplot2
knows the dimensions of labels plotted by geom_text
. Otherwise the check_overlap
option would not wor
If you are just looking to avoid overlapping labels, the ggrepel package works pretty well.
library(ggplot2)
library(ggrepel)
df <- data.frame(x = c(1, 2),
y = c(1, 1),
label = c("label-one-that-might-overlap-another-label",
"label-two-that-might-overlap-another-label"),
stringsAsFactors = FALSE)
ggplot(df, aes(x, y)) +
geom_text_repel(aes(label = label), check_overlap = F) +
xlim(0, 3)
The above code produces the graph below.