【问题标题】:Add custom vertical line joyplots ggridges添加自定义垂直线joyplots ggridges
【发布时间】:2018-01-23 02:38:28
【问题描述】:

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

【问题讨论】:

    标签: r ggplot2 ggridges ridgeline-plot


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 2021-01-21
      • 2017-07-14
      • 2019-05-05
      • 1970-01-01
      • 2021-12-28
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多