【问题标题】:Where can I find documentation on the `..*..` ggplot options?我在哪里可以找到有关 `..*..` ggplot 选项的文档?
【发布时间】:2013-09-04 18:39:00
【问题描述】:

我不时使用..density..,这很棒。在ggplot2..count.. 中有很多例子。通过stat_density documentation,我了解了..scaled..。看到有人在 StackOverflow 上使用 ..n..,我发现了这一点。现在我只是想知道我还缺少什么。

搜索引擎似乎忽略了“..n.. ggplot2”等搜索字符串中的.s,即使我将它们转义。这些变量有通用术语吗?还有更多吗?我在哪里可以找到有关它们的文档?

【问题讨论】:

  • 好吧,查看所有stat_* 函数的文档并查看“值”下的内容。
  • 您也可以使用 SymbolHound 来处理特殊字符。 (symbolhound.com/?q=..count..)
  • 欣赏 SymbolHound 链接,但有趣的是它只提供 SO 链接,而没有任何指向“真实”R 文档页面的链接。
  • Google 允许搜索一些标点符号,但不允许搜索句点:support.google.com/websearch/answer/2466433
  • +1。我想知道同样的事情。搜索这些命令真是太痛苦了......另外,感谢杰罗姆的链接。

标签: r ggplot2


【解决方案1】:

这里是 ggplot2 帮助文件中提到的所有..*.. 选项(或者至少是那些可以通过键入?"<func>" 调出的帮助文件,其中"<func>" 指的是一个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.."   

或者,要找出哪个帮助文件记录了哪个..*..,运行这个:

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]

【讨论】:

  • 太棒了。做得很好。访问帮助文档的文本将非常有用。
  • @DWin -- 好的,谢谢!我要感谢一辉,from whose gist(灵感来自this SO question)我首先拿起了其中的一些功能。
【解决方案2】:

截至 ggplot2 版本 3.3.0 (2020-03-05),(来自更新日志):

现在可以更精细地控制美学的评估时间。 after_stat() 取代了 stat()..var..-notation 的使用,并由 after_scale() 加入以允许映射到缩放的美学值。 stage() 现在支持重新映射相同的美学,因此您可以将数据变量映射到统计美学,并在统计转换后将相同的美学重新映射到其他东西

所以..var.. 变量没有实际意义,您应该尝试研究并改用after_stat

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多