如何将geom_point添加到stat_density_ridges [英] How to add geom_point to stat_density_ridges

查看:163
本文介绍了如何将geom_point添加到stat_density_ridges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用此代码绘制density_ridge.我想在不更改当前设计的情况下在0.50百分数处添加geom_point.任何帮助将不胜感激.

I am able to draw density_ridge using this code. I want to add geom_point at percentile 0.50 without changing the current design. Any help would be much appreciated.

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
  )

推荐答案

尝试

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

(沿途,您必须致电似乎是viridis 调色板)

(along the way you must have called viridis color palette it seems)

数据

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
  )

这篇关于如何将geom_point添加到stat_density_ridges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆