How to add geom_point to stat_density_ridges

不问归期 提交于 2020-03-19 07:44:50

问题


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
  )


回答1:


Try

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

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

data

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
  )


来源:https://stackoverflow.com/questions/60141618/how-to-add-geom-point-to-stat-density-ridges

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!