簡體   English   中英

添加標簽以分散 ggplot2 中的 plot 點

[英]Adding labels to scatter plot points in ggplot2

我無法使用 ggplot 向散點 plot 上的點添加標簽。 它不是添加國家名稱,而是添加行號。 我需要對 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))

在此處輸入圖像描述

這對你有用嗎:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM