0

How do I left justify my label using geom_text_repel? In the example below, I would like the word "very" to be underneath the word "this". Here I use the left justify setting i.e., hjust = 0

library(tidyverse)
library(ggrepel)

mtcars %>% 
  ggplot(aes(hp, drat, label = "this label is so long \n very long \n very long")) +
  geom_line() +
  geom_text_repel(data = mtcars %>% 
                    filter(hp == max(hp)),
                  nudge_x = 0.4,
                  segment.color = 'transparent',
                  size = 3,
                  force =0.2,
                  hjust = 0)

enter image description here

I may need to approach this problem using annotate instead of ggrepel see - Justifying lines of text within individual ggrepel labels , but ggrepel would be preferable

Another option may be to use grid::grid.gedit, but I don't understand how to apply this framework to ggrepel see - ggplot2: How to left-justify text from multi-line facet labels?

Edit: The problem in this question is similar to Override horizontal positioning with ggrepel , but the questions differ in that here I use hjust = 0, whereas the other question uses hjust = "outward"

John-Henry
  • 1,556
  • 8
  • 20
  • 1
    I have to say it would be _expected behavior_ for `hjust = 0` to left-justify multiline labels / text, and `hjust = 1` to right-justify them. I can't think of a possible reason someone would want to left-justify their text (as shown in the `ggrepel` vignette) but have subsequent lines centered! If no one else has an easy solution, I would open an issue in the `ggrepel` github project. – Benjamin May 30 '19 at 15:06
  • 2
    See related problem here: https://stackoverflow.com/questions/56028991/override-horizontal-positioning-with-ggrepel/ – teunbrand May 30 '19 at 15:16

0 Answers0