# NOT RUN {
library(ggplot2)
# Examples of coloring by ecdf or quantiles
ggplot(iris, aes(x = Sepal.Length, y = Species, fill = factor(stat(quantile)))) +
stat_density_ridges(
geom = "density_ridges_gradient",
calc_ecdf = TRUE,
quantiles = 5
) +
scale_fill_viridis_d(name = "Quintiles") +
theme_ridges()
ggplot(iris,
aes(
x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5-stat(ecdf))
)) +
stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
scale_fill_viridis_c(name = "Tail probability", direction = -1) +
theme_ridges()
ggplot(iris,
aes(
x = Sepal.Length, y = Species, fill = factor(stat(quantile))
)) +
stat_density_ridges(
geom = "density_ridges_gradient",
calc_ecdf = TRUE, quantiles = c(0.025, 0.975)
) +
scale_fill_manual(
name = "Probability",
values = c("#FF0000A0", "#A0A0A0A0", "#0000FFA0"),
labels = c("(0, 0.025]", "(0.025, 0.975]", "(0.975, 1]")
) +
theme_ridges()
# }
Run the code above in your browser using DataLab