【问题标题】:Where to find documentation on the `fun` argument in `geom_line`?在 `geom_line` 中哪里可以找到有关 `fun` 参数的文档?
【发布时间】:2017-02-17 17:23:43
【问题描述】:

我正在学习有关 R 的 Udacity 课程,其中一个练习让我编写此代码以绘制散点图并覆盖一条“平均”线和三个“四分位数”线。

ggplot(aes(x = age, y = friend_count), data = pf) + 
  xlim(13, 90) +
  geom_point(alpha = 0.05, position  = position_jitter(h = 0), color = 'orange') +
  coord_trans(y = 'sqrt') +
  geom_line(stat = 'summary', fun.y = mean) +
  geom_line(stat = 'summary', fun.y = quantile, fun.args = list(probs = 0.1), color = 'blue', linetype = 2) +
  geom_line(stat = 'summary', fun.y = quantile, fun.args = list(probs = 0.5), color = 'blue', linetype = 2) +
  geom_line(stat = 'summary', fun.y = quantile, fun.args = list(probs = 0.9), color = 'blue', linetype = 2)

我想在geom_line 中查看fun 参数的文档,所以我查看了geom_line 的文档(R Studio 和在线),geom_line 函数显示为

geom_line(mapping = NULL, data = NULL, stat = "identity", position = "identity", 
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)

我在任何地方都看不到fun 参数。所以我的问题是:如果我还没有了解 Udacity 课程中的 fun 参数,我如何通过查看文档来了解它以及我如何获得更多信息?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    短版:

    ?stat_summary 中,我们找到了fun.y 参数。

    如何到达:

    首先检查?geom_line 中的参数。在那里我们找到了“省略号参数”...

    ... 传递给layer 的其他参数。

    然后点击链接到?layer:

    通常使用geom_*stat_* 创建层

    在您的情况下,您将包装器geom_line(而不是layer(geom = "line",)与stat = "summary" 一起使用。因此,后者将我们引向stat_summary

    最后,在?stat_summary 中,我们找到了fun.y 参数。

    【讨论】:

    • @BenRubin “它们也可能是成对的 geom/stat 的参数”:fun.y 参数用于 stat_summary,您会在那里找到它们的文档。
    猜你喜欢
    • 1970-01-01
    • 2020-11-08
    • 2020-08-15
    • 2011-01-16
    • 2015-02-21
    • 2020-10-06
    • 1970-01-01
    • 2012-11-05
    • 2015-08-16
    相关资源
    最近更新 更多