Skip to content
Prev 384014 / 398502 Next

how to show percentage of individuals for two groups on histogram?

Hi Ana,
This is a very common question about ggplot.
A quick search turns up lots of hits that answer your question. Here
are a couple
https://community.rstudio.com/t/trouble-scaling-y-axis-to-percentages-from-counts/42999
https://stackoverflow.com/questions/3695497/show-instead-of-counts-in-charts-of-categorical-variables
ggplot(a, aes(x = HBA1C, fill=pheno)) + geom_histogram(aes(y =
stat(density)), binwidth = 0.5) +
      scale_y_continuous(labels = scales::percent_format())

HTH,
Eric
On Fri, May 22, 2020 at 7:18 AM Jim Lemon <drjimlemon at gmail.com> wrote: