library(ggplot2)
library(distributional)
df = data.frame(
d = c(dist_normal(2.7, 1), dist_lognormal(1, 1/3)),
name = c("normal", "lognormal")
)
# map density onto alpha of the fill
ggplot(df, aes(y = name, xdist = d)) +
stat_slabinterval(aes(alpha = !!p_(x)))
# map CCDF onto thickness (like stat_ccdfinterval())
ggplot(df, aes(y = name, xdist = d)) +
stat_slabinterval(aes(thickness = !!Pr_(xdist > x)))
# map containing interval onto fill
ggplot(df, aes(y = name, xdist = d)) +
stat_slabinterval(aes(fill = !!Pr_(x %in% interval)))
# the color scale in the previous example is not great, so turn the
# probability into an ordered factor and adjust the fill scale.
# Though, see also the `level` computed variable in `stat_slabinterval()`,
# which is probably easier to use to create this style of chart.
ggplot(df, aes(y = name, xdist = d)) +
stat_slabinterval(aes(fill = ordered(!!Pr_(x %in% interval)))) +
scale_fill_brewer(direction = -1)
Run the code above in your browser using DataLab