我想使用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,为setosa添加5。关于如何做的任何想法?
答案 0 :(得分:2)
由于您的密度不重叠,因此最简单的方法是添加其他细分。
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)