首页 > 解决方案 > R:将选择标签附加到条形图中的多个组件图

问题描述

我的数据如下:

> wef_20
# A tibble: 156 x 7
   Country   Year `Economic Participatio… `Educational Attainme… `Gender Gap Sco…
   <chr>    <int>                   <dbl>                  <dbl>            <dbl>
 1 Lao PDR   2021                   0.915                  0.965            0.75 
 2 Bahamas   2021                   0.857                  1                0.725
 3 Burundi   2021                   0.855                  0.896            0.769
 4 Iceland   2021                   0.846                  0.999            0.892
 5 Belarus   2021                   0.84                   0.999            0.758
 6 Guinea    2021                   0.839                  0.68             0.66 
 7 Barbados  2021                   0.837                  0.991            0.769
 8 Latvia    2021                   0.822                  1                0.778
 9 Benin     2021                   0.814                  0.733            0.653
10 Moldova   2021                   0.811                  0.996            0.768
# … with 146 more rows, and 2 more variables: Health and Survival Score <dbl>,
#   Political Empowerment Score <dbl>

使用以下脚本:

library(readr)
library(scales)
wef <- read_csv("Documents/Code/ceda/wef_gg_combined.csv", 
                col_types = cols(Year = col_integer()))
wef_20 <- subset(wef, Year==2021)
list <- list('Gender Gap Score'=wef$`Gender Gap Score`, 
             'Economic\nParticipation Score'=wef$`Economic Participation Score`,
             'Educational\nAttainment Score'=wef$`Educational Attainment Score`,
             'Health &\nSurvival Score'=wef$`Health and Survival Score`,
             'Political\nEmpowerment Score'=wef$`Political Empowerment Score`)
par(mar=c(5,10,4,1)+0.1)
stripchart(list,
xlim=c(0,1),
col=alpha(c("dark blue"), I(1/10)),
pch='|',
las=1,
xaxs='i',
cex=1.5,
offset=50)

我能够生成这个条形图:

在此处输入图像描述

我希望标记一些国家(比如几个定义的国家,例如印度、中国、美国、日本),它们将位于条形图上,类似于:

在此处输入图像描述

我不知道如何将一个国家附加到每个组件图上的每个点,然后只显示几个选定国家的标签。

标签: rdataframeggplot2data-visualizationstripchart

解决方案


推荐阅读