Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

ggplot2

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?

like image 893
Gregor Thomas Avatar asked Sep 04 '13 18:09

Gregor Thomas


People also ask

What library contains Ggplot?

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.

How do I get Ggplot in R?

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.

Is Ggplot and ggplot2 the same?

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'.

What does Ggplot () do?

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.


1 Answers

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]
like image 140
Josh O'Brien Avatar answered Sep 26 '22 01:09

Josh O'Brien