我想使用ggridges逐行添加一条垂直线到joy plots。
# 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)我想在virginica的7处,杂色的4处,setosa的5处添加一条垂直线。你有什么建议吗?
发布于 2018-01-23 11:47:29
因为你的密度不会重叠,所以最简单的方法就是添加额外的线段。
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)

https://stackoverflow.com/questions/48393348
复制相似问题