Adding labels to scatter plot points in ggplot2

Viewed 42

I am having trouble adding labels to points on a scatter plot using ggplot. Instead of adding the country name, it is adding the row number. What changes to geom_text do I need to make to fix this?

ggplot(data = World, aes(x = pop_age, y = peace_index_score, label = country)) + geom_point() + labs(title = "Youth Buldge and Instability", x = "Median Age in Country",y = "Overall Peacefulness of Country") + theme_economist() + ylim(0,4) + xlim(15,45) + geom_smooth(method = lm, color = "red") + geom_text(aes(label=country))

enter image description here

1 Answers

Is this working for you:

ggplot() + 
 geom_point(data = World, aes(x = pop_age, y = peace_index_score)) + 
 labs(title = "Youth Buldge and Instability", x = "Median Age in Country",y = "Overall Peacefulness of Country") + 
 theme_economist() + 
 ylim(0,4) + 
 xlim(15,45) + 
 geom_smooth(data = World, aes(x = pop_age, y = peace_index_score), method = lm, color = "red") + 
 geom_text(data = World, aes(x = pop_age, y = peace_index_score, label = country))

Related