首页 > 解决方案 > NA 作为 aes_string 中的输入

问题描述

根据我的代码,当不提供应该在 aes_string 中定义的所有变量时,我也想执行 aes_string 函数。编码:

test <- function(data, x, y, c){
    ggplot(data = data, mapping = aes_string(x = x, y = y, colour = c))
}

当我没有任何颜色变量作为输入时,我也希望能够执行它,例如:

test(data, 'x', 'y', NA)

或者

test(data, 'x', 'y', '')

或类似的,但我不知道我可以输入哪个值作为 ggplot 不考虑它的 c。

标签: rggplot2

解决方案


test(data, 'x', 'y', FALSE)

做了这份工作。


推荐阅读