I would like to add vertical segments to a ridgeline plot whose histograms show customized quantiles.
I managed to get the vertical segments if I map fill color with ..x..
. But I would like to show quantiles in the density plots. I wrote the following code:
library(datasets)
library(ggplot2)
data("iris")
iris_lines <- data.frame(Species = c("setosa", "versicolor", "virginica"),
x0 = c(5, 5.9, 6.5))
Figure1 <- ggplot(iris, aes(x=Sepal.Length, y=Species, fill=(..quantile..))) +
geom_density_ridges_gradient(jittered_points = FALSE, calc_ecdf = TRUE, quantile_lines = c(TRUE), quantiles =c(0.1,0.25,0.75,0.9),scale=0.9, color='white')+
geom_segment(data = iris_lines, aes(x = x0, xend = x0, y = as.numeric(Species), yend = as.numeric(Species) + c(.9,.5,.5)), color = "red") + scale_y_discrete(expand = c(0.01, 0))
Figure1
The code works if I map fill color as fill = ..x..
I get three vertical lines representing the mean of each density plot; however, if I map fill color as fill = ..quantile..
I get the following error:
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 1, 3