Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将R中两行的值合并在一起_R_Tidyverse - Fatal编程技术网

如何将R中两行的值合并在一起

如何将R中两行的值合并在一起,r,tidyverse,R,Tidyverse,我正在尝试将两行合并在一起,但似乎找不到方法 我使用了geom_col(),有两行。一个标签为“尼日利亚”,另一个标签为“尼日利亚”。我想将这两行的“sum_gt”值合并为一行 这是我的密码: plastics %>% select(country, year, grand_total) %>% filter(country != "EMPTY") %>% drop_na(grand_total) %>% group_by(country) %&g

我正在尝试将两行合并在一起,但似乎找不到方法

我使用了geom_col(),有两行。一个标签为“尼日利亚”,另一个标签为“尼日利亚”。我想将这两行的“sum_gt”值合并为一行

这是我的密码:

plastics %>% 
select(country, year, grand_total) %>%
filter(country != "EMPTY") %>% 
drop_na(grand_total) %>%
group_by(country) %>% 
summarize(sum_gt = sum(grand_total)) %>%
arrange(desc(sum_gt)) %>% 
ggplot(aes(reorder(x = country, sum_gt), y = sum_gt, fill = country)) +
geom_col() +
coord_flip() +
theme(legend.position = "none")
数据集来自TidyTuesday,以下是URL:


塑料如果要求和,它们必须有相同的名称。数据集中还有“厄瓜多尔”和“厄瓜多尔”。为了确保您能抓住所有的情况,我建议您在开始配管之前执行以下操作:

plastics$country<- tolower(plastics$country)

plastics$country或者,将
groupby(国家)
更改为
groupby(国家=tolower(国家))