Reputation: 19
I am using trying to merge 2 rows together but cannot seem to find a way.
I have used geom_col() and there are two Nigeria rows. One is labelled "Nigeria" and other is "NIGERIA". I want to merge the values of "sum_gt" for these 2 rows together as a single row.
Here is my code:
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")
the dataset is from TidyTuesday and here is the URL:
plastics <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-26/plastics.csv')
Upvotes: 0
Views: 87
Reputation: 723
They must have the same name, if you want to sum them. There is also "ECUADOR" and "Ecuador" in your dataset. To be sure that you catch all the cases I suggest you do the following before you start your piping:
plastics$country<- tolower(plastics$country)
Upvotes: 1