This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ggplot histogram normalize the tallest bin to 1 and adjust all others accordingly?

I have multiple samples (types) and I want to plot there values on the same histogram. I can do this but because the groups are very different in the number in each type, I think the very different heights of the bars could hiding a small difference between the groups. So I wanted to change the plot so that the highest peak (bin) is set to 1, all others are reduced accordingly. This is done for each Type so that the tallest bin in each is the same and they should be more comparable. I tried using density to get this, but it did not give the desired outcome.

ggplot(df, aes(x = length)) + 
 geom_histogram(data=subset(df, Type == 'A'), fill = "#F8766D", alpha = 0.6) +
  geom_histogram(data=subset(df, Type == 'B'), fill = "#7CAE00", alpha = 0.6) +
  geom_histogram(data=subset(df, Type == 'C'), fill = "#00BFC4", alpha = 0.6) +
  geom_histogram(data=subset(df, Type == 'D'), fill = "#C77CFF", alpha = 0.6) + 
  scale_x_log10(breaks=c(0,10,100,1000,10000))
ggplot r plots histogram

Could you provide some example data?

1 answer

Try this:

ggplot(df, aes(x = length)) + geom_histogram(aes(y = ..ncount..))

(add this aes field with y=..ncount.. to all your histogram calls)

Log in to answer this question.