When I run this code it sort of gives me almost everything I want, except that I can't, however, seem to figure out how to change the y-axis to show proportion instead of count. I appreciate any suggestion. Thanks!
to get the proportions you want stat_count() requires to have just one group so you cant apply fill = cyl, if you want more flexibility, calculate the proportions yourself and use geom_col()
library(tidyverse)
ggplot(data = mpg) +
geom_bar(mapping = aes(x = factor(cyl), y = stat(prop), group = 1), stat = "count") +
geom_text(mapping = aes(label = stat(scales::percent(prop)), x = factor(cyl), y = stat(prop), group=1), stat = "count", vjust=-.5)
Calculating the proportions separately works. I was just wondering if there is a way to plot using the original data set without having to go through that intermediate step. If there's not, that's not a big deal. Thanks!
This is awesome. Could you please point me to some resources where I can learn some more about the stage() function and also the stat argument? I feel like I'm not having a good grasp of either. Thanks so much!