I have this plot
ggplot(data, aes(D3)) +
geom_histogram(aes(fill=(..count..)/sum(..count..)), stat = "count", na.rm = TRUE, binwidth =1) +
geom_text(aes(y = ((..count..)), label = scales::percent( (..count..)/sum(..count..)) ), stat = "count", vjust = -0.25) +
scale_fill_gradient("", low = "green", high = "red")
which outputs a this nice histogram
as you can see y axis shows count instead of percentage.
On other hand if I switch to
ggplot(data, aes(D3)) +
geom_histogram(aes(y = (..density..)), binwidth = 1) +
geom_text(aes( label = format(100*..density.., digits=1,), y= ..density.. ), stat= "bin", binwidth =1, vjust = -0.2 ) +
scale_y_continuous(labels = scales::percent)
it outputs this (quite ugly) plot with zeroes on the y axis
How can I adjust y-axis on first plot, ie show percentage instead count? or remove those zeroes in the second?