I've recently learned about the ..level.. feature of stat_density_2d(). For example:
plot_data <-
data.frame(X = c(rnorm(300, 3, 2.5), rnorm(150, 7, 2)),
Y = c(rnorm(300, 6, 2.5), rnorm(150, 2, 2)),
Label = c(rep('A', 300), rep('B', 150)))
ggplot(plot_data, aes(X, Y)) +
stat_density_2d(geom = "polygon", aes(alpha = ..level.., fill = Label))
I searched both the ggplot2 github and the reference documentation , and can not find sources for ..level.. and if there are additional interesting ..dotdot.. "hidden" features.
