As shown in the plot below, the state names are sometimes far from the line. One option to consider is not to put the labels next to the lines, but instead to include them in a box at the top right-hand corner of the figure. How can I do this?
Here is the part of my codes that I believe need to be modified.
geom_line(aes(x =Year, y = Age.Adjusted.Rate, colour = State), data = d_filtered_top5_fe)+
ggrepel::geom_text_repel(aes(x =Year, y = Age.Adjusted.Rate, colour = State, label = State, fontface = 'bold'), data = d_filtered_top5_fe %>%
filter(Year == max(Year)),
segment.color = 'transparent',
size = 2.5
) +