I am working with geom_density_ridges function in ggplot to get different distributions along the y-axis. Below you can find a reproducible example:
datatype = data.frame(x = c(rnorm(40,0,0.5),rnorm(40,0.5,1),rnorm(40,2,1),rnorm(40,1,1)),
within = c(rep('TypeA',40),rep('TypeB',40),rep('TypeA',40),rep('TypeB',40)),
between = c(rep('BetweenA',80),rep('BetweenB',80)))
p = ggplot(datatype, aes(x = x, y = between)) +
geom_density_ridges(aes(fill = within),alpha =.7,scale =.9,size=.3,show.legend = F)+
theme_bw()
The problem is that I cannot find a way to also add the density values on the y-axis, so that I can show in my plot how frequent are the x-values in each distribution.
Any idea on how to solve this? However, I would like to stick with geom_density_ridges, since I have already made several plots with it.