ggplot histogram normalize the tallest bin to 1 and adjust all others accordingly?
1
0
Entering edit mode
8.1 years ago
james.lloyd ▴ 100

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 • 6.8k views
ADD COMMENT
0
Entering edit mode

Could you provide some example data?

ADD REPLY
2
Entering edit mode
8.1 years ago

Try this:

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

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

ADD COMMENT

Login before adding your answer.

Traffic: 2027 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6