I have a ridge plot made with the ggridges
package, using the stat = 'binline'
argument to plot a histogram for each group. I would like to show the counts for each group on a secondary y-axis at left, with at least one or two axis ticks per group. I cannot find any examples where this has been done. I know it is not straightforward because of the way the y-axis is constructed in ggridges
. Is there a relatively easy way to do this?
Code:
set.seed(1)
fakedat <- data.frame(x = sample(1:10, size = 100, replace = TRUE),
g = letters[1:4])
library(ggplot2)
library(ggridges)
ggplot(fakedat, aes(x = x, y = g)) +
geom_density_ridges(stat = 'binline', bins = 10, scale = 0.9) +
theme_ridges()
Plot:
Desired output would be to have ticks going up the left side that begin at zero at the baseline of each group and show the counts in the histogram bins.