Open kissmyjazz opened 5 years ago
I would need a specific example to understand what exactly you are requesting.
For any examples you prepare, please use the reprex package and follow their guidelines on minimal examples.
I have a count variable binned into time periods. I represent counts with the geom_density_ridges() with stat "identity". I also have a second variable that I would like to represent which specifies the onset of an event for each observation. Now these data is represented below ridges by green bars by using geom_segment(). I would like to map those segments over the ridges because each ridge is associated with the specific onset. Sorry, I could not find the built in dataset that represents similar data structure.
library(ggplot2)
library(ggridges)
d <- data.frame(x = rep(1:5, 3), y = c(rep(0, 5), rep(1, 5), rep(2, 5)),
height = c(0, 1, 3, 4, 0, 1, 2, 3, 5, 4, 0, 5, 4, 4, 1),
path = rep(1:3, 5))
ggplot(d, aes(x, y, height = height, group = y)) +
geom_density_ridges(stat = "identity", scale = 1) +
geom_segment(data = d, aes(x = path, xend = path, y = height, yend = height-0.5),
color = "green3")
Created on 2019-07-09 by the reprex package (v0.3.0)
How can I map the height of green bars to match the height of the ridges?
By inspecting the y axis scale, you should be able to deduce how you can scale the green bars so they fit. Overall, this doesn't look like a feature that makes sense to add to ggridges.
ggridges already scales quantile bars to a proper height. How can I extract scaled y height information from the ggridges object?
Hello, Thank you for the wonderful package! I saw that it is possible to plot quantile segments on ridge densities, but I would like to plot vertical segments where x coordinates come from my data frame and y coordinates are matched to the height of ridge density in a grouped data at a particular x coordinate. I could not figure out how to map ggplot's geom_segment into the coordinate space of ridge densities.