添加自定义垂直线 joyplots ggridges

Add custom vertical line joyplots ggridges

我想使用 ggridges.

逐行向欢乐图添加垂直线
# toy example
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=..x..)) +
geom_density_ridges_gradient(jittered_points = FALSE, quantile_lines = 
FALSE, quantiles = 2, scale=0.9, color='white') +
scale_y_discrete(expand = c(0.01, 0)) +
theme_ridges(grid = FALSE, center = TRUE)

我想在 7 处添加一条竖线表示 virginica,4 处表示云芝,5 处表示 setosa。有什么想法吗?

由于您的密度不重叠,因此最简单的方法可能是只添加额外的细分。

iris_lines <- data.frame(Species = c("setosa", "versicolor", "virginica"),
                         x0 = c(5, 4, 7))

ggplot(iris, aes(x=Sepal.Length, y=Species, fill=..x..)) +
  geom_density_ridges_gradient(jittered_points = FALSE, quantile_lines = 
                                 FALSE, quantiles = 2, scale=0.9, color='white') +
  geom_segment(data = iris_lines, aes(x = x0, xend = x0, y = as.numeric(Species),
                                      yend = as.numeric(Species) + .9),
               color = "red") +
  scale_y_discrete(expand = c(0.01, 0)) +
  theme_ridges(grid = FALSE, center = TRUE)