[英]Adding labels to scatter plot points in ggplot2
I am having trouble adding labels to points on a scatter plot using ggplot.我无法使用 ggplot 向散点 plot 上的点添加标签。 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?我需要对 geom_text 进行哪些更改才能解决此问题?
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))
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.