当我在包中使用函数时,我通常可以将其写成形式function()或function不带括号。似乎不是这种情况scales::comma。为什么第 7 行在下面有效,而第 8 行却没有。
library(tidyverse)
mtcars %>%
count(cyl) %>%
ungroup() %>%
mutate(n = n * 1000) %>%
ggplot(aes(cyl, n)) +
scale_y_continuous(labels = scales::comma) + # line 7
# scale_y_continuous(labels = scales::comma()) + # line 8
geom_line()
Run Code Online (Sandbox Code Playgroud)
第 8 行错误
Error in number(x = x, accuracy = accuracy, scale = scale, prefix = prefix, :
argument "x" is missing, with no default
Run Code Online (Sandbox Code Playgroud)
这是取自scale_y_continuous有关输入参数的帮助页面labels:
标签 之一:
在这种情况下,最后一个是重要的。标签需要一个函数scales::comma。scales::comma()另一方面是该函数返回但不再是函数的内容。
| 归档时间: |
|
| 查看次数: |
1291 次 |
| 最近记录: |