Hi,
I'm trying to plot prevalence for a group of age-ranges and can do so but prevalence for each bin (age_group) is as % of entire population rather than for the number of people within the bin. Any ideas how to amend code below, is it somewhere in the summarise or mutate(pct lines?
Thanks
trimmed_df %>%
group_by(age_group, MM_binary) %>%
summarise(n = n(age_group)) %>%
mutate(pct = round(n/sum(n)*100, 1)) %>%
ggplot(aes(x = age_group, y = pct)) +
geom_col() +
scale_y_continuous(limits = c(0, 70),
breaks = scales::pretty_breaks(),
labels = scales::percent_format(scale = 1)) +
theme(legend.position = "top") +
labs(title = "Prevalence of MM by age",
y = "% of population",
x = "Age group", color = "grey20", size = 20, angle = 90) -> figure_1
figure_1