3

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
  )

enter image description here

markus
  • 25,843
  • 5
  • 39
  • 58
Krantz
  • 1,424
  • 1
  • 12
  • 31

1 Answers1

4

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)

enter image description here

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
  )
markus
  • 25,843
  • 5
  • 39
  • 58