Stacked bar chart in R (ggplot2) with y axis and bars as percentage of counts

For the first graph, just add position = ‘fill’ to your geom_bar line !. You don’t actually need to scale the counts as ggplot has a way to do it automatically.

ggplot(dat, aes(x = fruit)) + geom_bar(aes(fill = variable), position = 'fill')

Leave a Comment