I would like to annotate a plot so as to show the totals for each column. For example
ggplot(diamonds, aes(clarity, fill=cut)) +
geom_bar(position="fill") +
scale_y_continuous(name="proportion")
This will produce a stacked barplot. However it is difficult to know what is n for each of the bars. I1,SI2 and so on. How can I annotate it so that, for each bar, n is displayed at the top?
The easiest way is to compute the totals before plotting, then adding them to the plot separately. First, we calculate columns totals:
Then we use
geom_textto add the totals: