Gregor Thomas
Gregor Thomas

Reputation: 146060

Where can I find documentation on the `..*..` ggplot options?

I use ..density.. from time to time, and it's great. There's lots of examples of it in the ggplot2 book, as well as ..count... Looking through the stat_density documentation, I learned about ..scaled... Seeing someone use ..n.. here on StackOverflow, I found out about that. Now I just wonder what else I'm missing.

Search engines seem to ignore the .s in search strings like "..n.. ggplot2", even if I escape them. Is there a general term for these variables? Are there more? Where can I find documentation on them?

Upvotes: 19

Views: 328

Answers (2)

Gregor Thomas
Gregor Thomas

Reputation: 146060

As of ggplot2 version 3.3.0 (2020-03-05), (from the changelog):

The evaluation time of aesthetics can now be controlled to a finer degree. after_stat() supersedes the use of stat() and ..var..-notation, and is joined by after_scale() to allow for mapping to scaled aesthetic values. Remapping of the same aesthetic is now supported with stage(), so you can map a data variable to a stat aesthetic, and remap the same aesthetic to something else after statistical transformation

So the ..var.. variables are moot, and you should try to research and use after_stat instead.

Upvotes: 0

Josh O'Brien
Josh O'Brien

Reputation: 162431

Here are all of the ..*.. options mentioned in the ggplot2 help files (or at least those help files that can be brought up by typing ?"<func>", where "<func>" refers to one of the functions exported by ggplot2).

library(ggplot2)

## Read all of the ggplot2 help files and convert them to character vectors
ex <- unlist(lapply(ls("package:ggplot2"), function(g) {
    p = utils:::index.search(g, find.package(), TRUE)
    capture.output(tools::Rd2txt(utils:::.getHelpFile(p)))
}))

## Extract all mentions of "..*.." from the character vectors
pat <- "\\.\\.\\w*\\.\\."
m <- gregexpr(pat, ex)    
unique(unlist(regmatches(ex,m)))
# [1] "..density.."  "..count.."    "..level.."    "..scaled.."   "..quantile.."
# [6] "..n.."   

Or, to find out which help files document which ..*.., run this:

library(ggplot2)

ex <- sapply(ls("package:ggplot2"), function(g) {
    p = utils:::index.search(g, find.package(), TRUE)
    capture.output(tools::Rd2txt(utils:::.getHelpFile(p)))
}, simplify=FALSE, USE.NAMES=TRUE)

res <- lapply(ex, function(X) {
    m <- gregexpr("\\.\\.\\w*\\.\\.", X)    
    unique(unlist(regmatches(X, m)))
})
res[sapply(res, length) > 0]

Upvotes: 21

Related Questions