I'm trying to make a bar graph and add to it the percentages of each category. However when I try to run the code I get the following error message:
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomLabel, :
object 'share' not found
Here is my code:
base3 %>%
group_by(country.x) %>%
summarise(total=sum(cost)) %>%
mutate(countrygroup=sapply(country.x,cathegorize), countries=sapply(country.x,reverse_cathegorize), share=total/sum(total)) %>%
ggplot() +
geom_bar(aes(x=reorder(countries,total),y=total,fill=countrygroup),colour = 'black', alpha = 0.5,stat="identity")+
geom_label(aes(x=reorder(countries,total),y=share),label = paste0(round((share), 3)*100, '%'))