Suppose I have some set of lines that I plot using ggplot
and geom_line
. I want to label these lines. I can do this using geom_dl
from the directlabels
package, but even with the provided method to avoid overlaps (e.g. "last.qp"
), I still think that the labels are two close together.
How can I increase the spacing between these labels (here, in the y direction), without manually specifying each of their locations using ggplot2::annotate
or something similar? I'm open to answers that don't involve the directlabels
package, but if possible I'd like to stick with it because it does 95% of the work of labeling lines quite well.
There's potentially a hint here in tiebreak.big
, but I couldn't get it to work...
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(tibble)
library(directlabels)
library(tidyr)
data <- tibble(x = 1:10) %>%
mutate(y1 = x^2) %>%
mutate(y2 = y1+0.5) %>%
gather(key = var, value = value, y1, y2)
ggplot(data, aes(x = x, y = value, color = var)) +
geom_line() +
geom_dl(aes(label = var), method = list(cex = 1.2, dl.trans(x = x + 0.2), "last.qp"))
ggrepel
package: cran.r-project.org/web/packages/ggrepel/vignettes/ggrepel.html – Pathology