【问题标题】:How to add geom_point to stat_density_ridges如何将 geom_point 添加到 stat_density_ridges
【发布时间】:2020-05-25 06:04:20
【问题描述】:

我可以使用此代码绘制密度脊。我想在不改变当前设计的情况下在百分位 0.50 处添加 geom_point。任何帮助将不胜感激。

library(ggplot2)
library(ggridges)

 ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
  stat_density_ridges(
    geom = "density_ridges_gradient", calc_ecdf = TRUE,
    quantiles = 4, quantile_lines = TRUE
  )

【问题讨论】:

    标签: r ggplot2 ggridges


    【解决方案1】:

    试试

    p + geom_point(data = aggregate(Sepal.Length ~ Species, iris, median),
                   aes(x = Sepal.Length, y = Species),
                   color = "red",
                   size = 5,
                   inherit.aes = FALSE)
    

    (一路上你一定是调用了viridis调色板)

    数据

    library(ggplot2)
    library(ggridges)
    
    p <- ggplot(iris, aes(x=Sepal.Length, y=Species, fill = factor(stat(quantile)))) +
      stat_density_ridges(
        geom = "density_ridges_gradient", calc_ecdf = TRUE,
        quantiles = 4, quantile_lines = TRUE
      )
    

    【讨论】:

      猜你喜欢
      • 2019-09-04
      • 1970-01-01
      • 2015-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多