I just want the percentages for each bar to show. I can create the histogram, but as soon as I add stat_bin() the bars vanish.
options(scipen = 9)
histvecbrk = seq(0,5000, by=500)
cleaned_data %>%
filter(distance < 5000 & distance > 0 & member_casual == "casual") %>%
ggplot(aes(x=distance)) +
geom_histogram(aes(y = after_stat(count / sum(count))), binwidth = 500, color = "#000000", fill = "#0099F8")+
scale_y_continuous(labels = scales::percent) +
scale_x_continuous(breaks = histvecbrk) +
theme(axis.text.x = element_text(angle = 45))
histogram, no labels
Then when I add stat_bin() for labels, I get this.
options(scipen = 9)
histvecbrk = seq(0,5000, by=500)
cleaned_data %>%
filter(distance < 5000 & distance > 0 & member_casual == "casual") %>%
ggplot(aes(x=distance)) +
geom_histogram(aes(y = after_stat(count / sum(count))), binwidth = 500, color = "#000000", fill = "#0099F8")+
stat_bin(aes(label = stat(count / sum(count))),geom = "text", vjust = -0.5, binwidth = 500) +
scale_y_continuous(labels = scales::percent) +
scale_x_continuous(breaks = histvecbrk) +
theme(axis.text.x = element_text(angle = 45))
histogram, with labels?
I’ve tried so many other things and this is as close as I have come. This is just a cry for help at this point.
Thanks.
New contributor
Barry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.