与此类似:pass function arguments to both dplyr and ggplot
我过去曾使用!! sym()而没有任何令人难忘的头痛。
但是,现在我尝试这个时出现错误:
library(rlang)
library(tidyverse)
diamond_plot <- function (data, group, metric) {
quo_group <- sym(group)
quo_metric <- sym(metric)
data %>%
group_by(!! quo_group) %>%
summarise(price = mean(!! quo_metric)) %>%
ggplot(aes(x = !! quo_group, y = !! quo_metric)) +
geom_col()
}
diamond_plot(diamonds, "clarity", "price")
错误是
Error in !quo_group : invalid argument type
我错过了什么吗?