【发布时间】:2017-01-27 02:23:21
【问题描述】:
我想做一系列的例子并尝试使用一个函数。如何控制是否使用形状、alpha、大小等?这是我正在使用的代码:
library(ggplot2)
ggplot_example <-
function(aesthetic, var){
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy,
aesthetic = get(var)))
}
ggplot_example("color", "hwy")
ggplot_example("color", "class")
ggplot_example("alpha", "cty")
ggplot_example("size", "cty")
现在get(aesthetic) = get(var) 正在引发错误,当我只使用aesthetic = get(var) 时,它会忽略aesthetic 参数。
【问题讨论】: