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?
ggplot2 is a package in the tidyverse collection whose sole motive is to create graphics. It is a well-known library in R based on the concept of layered grammar of graphics.
The ggplot2 package can be easily installed using the R function install. packages() . The above code will automatically download the ggplot2 package, from the CRAN (Comprehensive R Archive Network) repository, and install it.
You may notice that we sometimes reference 'ggplot2' and sometimes 'ggplot'. To clarify, 'ggplot2' is the name of the most recent version of the package. However, any time we call the function itself, it's just called 'ggplot'.
ggplot() initializes a ggplot object. It can be used to declare the input data frame for a graphic and to specify the set of plot aesthetics intended to be common throughout all subsequent layers unless specifically overridden.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With