I've looked at lots of questions on this but nothing seems to get it quite right.
I have this bar chart of soccer matches that's stacked to show which team had better or worse form and how that mapped to the result.
I want to add a label to each of the segments of the bars to show the total for that segment -- eg, 15 for "Blades and draw" -- and also a total for the bar at the top, ideally.
Here's the code used to create it:
ggplot(Sheff_derby_form_league, aes(x = Result)) +
geom_bar(aes(y = ..count.., fill = Res_vs_f_team)) +
labs(title = "Blades vs Owls. League derby form and result",
subtitle = "Team with form advantage a little more likely to win",
x = "Better form: > 0.33ppg over opponent. Even form: < 0.33ppg", y = "")
+ scale_fill_brewer(palette = "RdBu")