Как добавить geom_point в stat_density_ridges - PullRequest
3 голосов
/ 10 февраля 2020

Я могу нарисовать плотность, используя этот код. Я хочу добавить geom_point на процентиле 0,50 без изменения текущего дизайна. Любая помощь будет высоко ценится.

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
  )

enter image description here

1 Ответ

4 голосов
/ 10 февраля 2020

Попробуйте

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

(по пути вы должны были назвать viridis цветовая палитра, кажется)

enter image description here

данные

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
  )
...