1

Take the data "diamond" for example,

library(ggplot2)
library(ggridges)
ggplot(diamonds, aes(x = price, y = cut,fill = factor(stat(quantile)))) +
    stat_density_ridges(
        geom = "density_ridges_gradient", 
        calc_ecdf = TRUE,
        quantiles = 0.25) +
    theme_ridges() +
    scale_fill_manual(
        name = "Probability", values = c("#FF0000A0", "#A0A0A0A0"),
        labels = c("(0, 0.25]", "(0.25, 0.75]")
    )

This will plot 5 different densities overlap given categorical variable "cut" is mapped onto the y axis, the tail of quantile 25% in all 5 density ridges will be filled with red color "#FF0000A0", or "quantiles= 2" parameter will result in colored tail of 50% quantile.

But what I want is different quantile tail for each group in the "cut" variable, e.g. 10% tail for "Ideal", 20% for "Premium" ,30%for "Good ", 40%for"Very Good" ,and 50% for "Fair" . HOW to do this plot?

Zzx Zhang
  • 11
  • 1

0 Answers0