ggrepel: Change start point of segments

36 Views Asked by At

I am making a graph, with labels given by ggrepel. I have arranged it so that all the labels are at the far side of the graph, so as to not obscure any of the data. The issue is that the segments are winding up behind some of the other labels, making them hard to read.

Ideally I would like to force the segments to come out of the left side of each label. Currently, some are coming out of the top, which is in large part responsible for the problem.

How can I force the label segments to come out of the left of the labels, rather than the top?

Here is a screenshot of the relevant part of the graph: enter image description here

I want it to look something like this. I've drawn in a few big blue lines to give an idea:

enter image description here

I have tried adjusting various parameters for geom_label_repel, but these mostly seem to have to do with the size and position of the box around the label rather than the segment. For example, adjusting the label.padding parameter, which is mentioned in some similar questions on here, did this:

enter image description here

EDIT: Here is my code for geom_label_repel:

if (include.label == TRUE) {
    label <- 
      geom_label_repel(data = filter(plotdata,
                                     Year == 2023),
                       aes(x = Year,
                           y = Label_y_pos,
                           label = Country,
                           fill = Country,
                           segment.color = Country),
                       color = "black",
                       nudge_x = 5,
                       hjust = 0,
                       min.segment.length = 0,
                       direction = "y"
      )
0

There are 0 best solutions below