如何将R中两行的值合并在一起
我正在尝试将两行合并在一起,但似乎找不到方法 我使用了geom_col(),有两行。一个标签为“尼日利亚”,另一个标签为“尼日利亚”。我想将这两行的“sum_gt”值合并为一行 这是我的密码:如何将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
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(国家))