首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加自定义垂直线joyplots ggridges

添加自定义垂直线joyplots ggridges
EN

Stack Overflow用户
提问于 2018-01-23 10:38:29
回答 1查看 2.3K关注 0票数 5

我想使用ggridges逐行添加一条垂直线到joy plots。

代码语言:javascript
复制
# 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处添加一条垂直线。你有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-23 11:47:29

因为你的密度不会重叠,所以最简单的方法就是添加额外的线段。

代码语言:javascript
复制
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)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48393348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档