我不明白 .
在下面的代码中正在做或在哪里可以找到它的文档:
library(tidyverse)
ggplot(iris) +
geom_point(
aes(x=Sepal.Length, y=Sepal.Width),
data = . %>% filter(Species == 'setosa')
)
这似乎与 What does the dplyr period character "." reference? 中描述的用法完全不同。哪里
.
不会出现在最左边的位置。文档 here仅仅说
A pipeline with a dot (.) as LHS will create a unary function. This is used to define the aggregator function.
但这对我来说并不清楚,我希望获得更多信息。
最佳答案
这里的混淆实际上可能来自两个地方。
首先,是的,. %>% something()
语法创建一个接受一个参数的“一元”函数。所以:
. %>% filter(Species == 'setosa')
相当于function(.) filter(., Species == 'setosa')
这里的第二部分是 ggplot2
层实际上可以将函数作为它们的data
争论。从例如?geom_point
:The data to be displayed in this layer. There are three options:
...
A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.
所以传递给
geom_point
的函数将始终应用于默认绘图数据(即 ggplot()
中定义的数据)。请注意,您链接的问题涉及
.
的使用在 funs()
,这与其在此处的使用没有直接关系。
关于r - magrittr dot/period (".") 运算符在管道的最开始时会做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53436488/