'ggplot: plot relative frequency of two variables

I created this plot using this code:

ggplot(df, aes(x = Hour, fill = category)) +
          geom_bar(position = "dodge") +
          theme_light() +
          scale_fill_viridis_d(name = "category", direction=-1, labels = c("1", "2"), option = "C")

I now want to plot the relative frequency of the data for each category so that each category is 100%. Could someone help me at this point?

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source