'GGPlot, fill by proportion with a geom_col()

I am trying to make each column fill by the proportion of each type of medal (Bronze, Silver, Gold) in relation to the Medal_sum for each country.

Olympic_overall_tograph %>%
  filter(Medal_sum>60) %>%
  mutate(Country_name = factor(Country, levels=c("Russia", "United States", "Australia", "Germany", "China", "Netherlands", "Cuba", "Brazil"))) %>%
  ggplot(aes(x=Country_name, y=Medal_sum, fill = variable)) +
  labs(title = "Winningest Countries in the World", xlab = "Country", ylab = "Total Medal Count") +
  geom_col()

I understand that the current fill is of equal 1/3 proportions because it is just taking the Bronze, Silver, and Gold and saying it is one of the three variables. I can't figure out how to get the fill to recognize that each is a proportion of the sum, and when I make a column that is a proportion of the medal for each medal type, the fill gives a broken type of gradient.

Graph: Graph

What the data looks like: What the data looks like

Also, I can't figure out how to upload my data, not sure if that is even possible. Anyway, that is what it looks like.



Solution 1:[1]

I can't confirm since I don't have the data, but you could try:

ggplot(aes(x=Country_name, y=value, fill = variable)) +
  labs(title = "Winningest Countries in the World", xlab = "Country", ylab = "Total Medal Count") +
  geom_col(position = "fill")

geom_col(position = "fill") will convert the value counts to proportions.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 bjorn