我试图创建ggplot
周围的包装,让我增加一些美感,如x变量或颜色,但总是prefills y
,ymin
和ymax
不必工作带有引用的变量名称。混合点和命名参数的函数调用的AES GGPLOT2
由于GGPLOT2不能用整洁的评价我都用NSE在这一点,但我坚持,信息我能找到here和here和检查的一些功能让我尝试之类的东西unlist(...)
与match.call()
工作。但他们只会抛出不同的错误。
在下面的功能我基本上希望能够调用ci_plot()
或例如ci_plot(color = cyl)
library(dplyr)
library(ggplot2)
library(purrr)
library(tidyr)
ci_plot <- function(data, ...) {
ggplot(data, aes(..., y = y, ymin = ymin, ymax = ymax))
}
mpg %>%
group_by(manufacturer) %>%
nest() %>%
mutate(x = map(data, ~mean_se(.x$hwy))) %>%
unnest(x) %>%
ci_plot() +
geom_pointrange()
这可能帮助代码:https://stackoverflow.com/questions/15458526/r-pass-variable-column-indices-to -ggplot2 – Wave