0

I am learning R for visualization, and come across this example:

ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))

The result will show proportionally instead of count, but I don't understand how this works. Could someone please explain to me what is this syntax ..something..do ?

w00d
  • 5,416
  • 12
  • 53
  • 85
  • 3
    The `..xxx..` construction represents variables computed internally by ggplot. For example, look at the "computed variables" section of the [help for `geom_bar`](https://ggplot2.tidyverse.org/reference/geom_bar.html). – eipi10 Sep 11 '18 at 20:28
  • Is it specific to ggplot ? or Is it something meaningful in R? why not just `y = prop` – w00d Sep 11 '18 at 20:30
  • 2
    It's specific to ggplot. I'm not certain of the reason for the `..`, but I'd guess it was to avoid confusion with other functions or objects that have the same name. – eipi10 Sep 11 '18 at 20:31
  • 3
    The `..` notation was deprecated in the latest release of `ggplot2` in favor of `stat()` – camille Sep 11 '18 at 20:50
  • Sure it's somewhat duplicated, but why downvote ? – w00d Sep 12 '18 at 02:53
  • @camille: how would you write the above statement in `ggplot2` with `stat()` ? – w00d Sep 12 '18 at 02:54
  • You would use it like `stat(prop)` instead of `..prop..`. It's documented at `?stat` – camille Sep 12 '18 at 03:48

0 Answers0