# NOT RUN {
library(ggplot2)
# Examples of coloring by ecdf or quantiles
library(viridis)
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=factor(..quantile..))) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = 5) +
scale_fill_viridis(discrete = TRUE, name = "Quintiles") + theme_ridges() +
scale_y_discrete(expand = c(0.01, 0))
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=0.5 - abs(0.5-..ecdf..))) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
scale_fill_viridis(name = "Tail probability", direction = -1) + theme_ridges() +
scale_y_discrete(expand = c(0.01, 0))
ggplot(iris, aes(x=Sepal.Length, y=Species, fill=factor(..quantile..))) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE,
quantiles = c(0.05, 0.95)) +
scale_fill_manual(name = "Probability\nranges",
values = c("red", "grey80", "blue")) +
theme_ridges() + scale_y_discrete(expand = c(0.01, 0))
# }
Run the code above in your browser using DataLab