I do a histogram in percentages (which works well) but when I try to print the value of the percentages, the scale of the y axis is not right anymore.
The code for the histogram in percentages (which works well) is the following :
data_impact_final %>%
ggplot(aes(x = time_to_treat_month)) +
geom_histogram(aes(y = (..count..)/sum(..count..)),binwidth=6) +
scale_y_continuous(labels = scales::percent)
However, when I try to print the percentages on the graph using stat_bin, the scale of the y axis is not right anymore. Here is the code I use to print the percentages :
data_impact_final %>%
ggplot(aes(x = time_to_treat_month)) +
geom_histogram(aes(y = (..count..)/sum(..count..)),binwidth=6) +
stat_bin(binwidth=6, geom='text', color='white', aes(label = scales::percent((..count..)/sum(..count..))),position=position_stack(vjust = 0.5))+
scale_y_continuous(labels = scales::percent)
Thank you for your help

