Хороший график!
Добавьте inherit.aes = F
ко второму геому, чтобы он не пытался сопоставить ваши данные с вычислением заполнения в вызове ggplot(aes()
.
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", inherit.aes = F) + #### HERE ####
scale_y_discrete(expand = c(0.01, 0))
Figure1

Редактировать:
ОП спросил в комментарии о выборочной маркировке некоторых элементов и добавлении метки для срединной линии.Вот подход, вероятно, не самый содержательный.
Figure1 <- ggplot(iris, aes(x=Sepal.Length, y=Species,
fill = (..quantile..),
color = (..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, fill = "median",
y = as.numeric(Species),
yend = as.numeric(Species) + c(.9,.5,.5),
color = "median")) + #### HERE ####
scale_y_discrete(expand = c(0.01, 0)) +
scale_color_manual(name = "quantile",
limits = c(1:3, "median"),
values = alpha("firebrick1", c(0, 0, 0, 1)),
labels = c("<10%", "10-25%", "IQR", "median")) +
scale_fill_manual(name = "quantile",
limits = c(1:3, "median"),
values = c("cadetblue", "coral", "orange", "white"),
na.value = "gray30",
labels = c("<10%", "10-25%", "IQR", "median"))
Figure1
