Q:

ggplot2: plot correct proportions using geom_bar

I am trying to plot proportion of diamonds using geom_bar and position = "dodge". Here is what I have done.
library(ggplot2)

ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut))

The image below tell me how many diamonds are there for each cut type. 

Now let's do something fancy.
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge")

The image below provides count of by grouping diamonds by clarity for each cut type.

What I would like to do is get the same dodge plot as above but showing proportion instead of count. 
For example, for cut=ideal and clarity = VS2, the proportion should be 5071/21551 = 0.23.

A:

You can try
library(tidyverse)
diamonds %>%
  count(cut, clarity) %>% 
  group_by(cut) %>% 
   mutate(Sum=sum(n)) %>% 
   mutate(proportion = n/Sum) %>% 
  ggplot(aes(y=proportion, x=cut,fill=clarity)) +
   geom_col(position = "dodge")

