You can try geom_text_repel()
from the ggrepel
package
library(tidyverse)
library(ggrepel)
# Sample data on a copy/paste friendly format
datos <- data.frame(
stringsAsFactors = FALSE,
country_name = c("Argentina","Bolivia",
"Brazil","Chile","Colombia","Ecuador","Paraguay","Peru",
"Uruguay","Argentina","Bolivia","Brazil","Chile",
"Colombia","Ecuador","Paraguay","Peru","Uruguay",
"Argentina","Bolivia"),
country_code = c("ARG","BOL","BRA","CHL",
"COL","ECU","PRY","PER","URY","ARG","BOL","BRA",
"CHL","COL","ECU","PRY","PER","URY","ARG","BOL"),
year = c(1990L,1990L,1990L,1990L,
1990L,1990L,1990L,1990L,1990L,1991L,1991L,1991L,
1991L,1991L,1991L,1991L,1991L,1991L,1992L,1992L),
value = c(1,1,1,1,1,1,1,1,1,1.08,
1.03,0.997,1.06,1,1.02,1.01,1,1.03,1.15,1.03)
)
ggplot(datos,aes(x = year, y = value, group = country_code, label = country_code)) +
geom_line(size=1.25,color="grey") +
geom_point(color="grey")+
geom_text_repel(data = . %>% group_by(country_name) %>% filter(year==max(year)),
nudge_x=0.1, hjust=0.5,vjust=(-0.5),color="grey") +
scale_x_discrete(breaks=c(1990,1995,2000,2005,2010,2015,2019))
Created on 2020-08-08 by the reprex package (v0.3.0)
BTW, next time please share sample data on a copy/paste friendly format, here is how to do it