0

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))

enter image description here

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.

M.Viking
  • 5,067
  • 4
  • 17
  • 33
  • 1
    Related to https://stackoverflow.com/questions/17502808/double-dots-in-a-ggplot – akrun Mar 22 '21 at 20:06
  • 1
    As of ggplot2 version 3.3.0, the `..var..` variables are superseded, and the preferred way is to use `after_stat()`. – Gregor Thomas Mar 22 '21 at 20:20
  • This answer worked in a previous version of ggplot2 - https://stackoverflow.com/a/18622577/10276092 - however, now the documentation does not contain any references to "..anything..". – M.Viking Mar 22 '21 at 20:23

0 Answers0