gpt4 book ai didi

r - 添加自定义垂直线joyplots ggridges

转载 作者:行者123 更新时间:2023-12-01 03:16:44 24 4
gpt4 key购买 nike

我想使用 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 添加一条垂直线,为 versicolor 添加 4 条,为 setosa 添加 5 条垂直线。关于如何做到这一点的任何想法?

最佳答案

由于您的密度不重叠,因此添加额外的段可能是最简单的。

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)

enter image description here

关于r - 添加自定义垂直线joyplots ggridges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48393348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com