How to label the count of each bin within ggridges package?

I have a data frame that simulates the NFL season with 2 columns: team and rank. I am trying to use ggridges to make a distribution plot of the frequency of each team at each rank from 1-10. I can get the plot working, but I'd like to display the count of each team/rank in each bin. I have been unsuccessful so far.

   ggplot(results, 
       aes(x=rank, y=team, group = team)) +
   geom_density_ridges2(aes(fill=team), stat='binline', binwidth=1, scale = 1.25, draw_baseline=T) +
   scale_x_continuous(limits = c(0,11), breaks = seq(1,10,1)) +
   theme_ridges() +
   theme(legend.position = "none") +
   scale_fill_manual(values = c("#4F2E84", "#FB4F14",  "#7C1415", "#A71930", "#00143F", "#0C264C", "#192E6C", "#136677", "#203731"), name = NULL)

Which creates this plot:

enter image description here

I tried adding in this line to get the count added to each bin, but it did not work.

   geom_text(stat='bin', aes(y = team + 0.95*stat(count/max(count)),
                         label = ifelse(stat(count) > 0, stat(count), ""))) +


from Recent Questions - Stack Overflow https://ift.tt/3mwdCSt
https://ift.tt/34xdpbk

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)