R ggplot2 x轴上最大值的名称

R ggplot2 the names of the biggest values on x axis

你好)谁能帮帮我。我有一个大 DF,有两列 Country_dest 和 SumTotal(是值),试图使用 qplot 函数

qplot(country_dest, SumTotal, data=Africa) 

Brunei       58
Aruba        73
Cuba         95
Nicaragua    97
Turkmenistan 99
Saint Lucia  102
Honduras    153
Barbados    161
Haiti   165
Montenegro  175

我想画一个图,但是在 x 轴上输入 SumTotal 值最高的国家(例如其中 7 个或 6 个)的名称,可以吗?)

提前致谢!

使用 ggplot,只需按人口重新排序:

ggplot(data = Africa, aes(x= reorder(country_dest, -SumTotal), y= SumTotal)) + geom_bar(stat = "identity")

如果你只想说前 5 名使用排列然后子集:

require(dplyr)
Africa.ordered <- arrange(Africa, -SumTotal)
Africa.top5 <- Africa.ordered[1:5,]

然后画出你的情节