我正在使用HighChart作为绘图工具创建一个函数。但是,当我在hcaes()函数中使用全局变量时,没有任何内容被绘制出来。让我们以mtcars数据集为例。
x = "mpg"
y = "hp"
hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))
#I am also attempting
hchart(mtcars, "point", hcaes(x = eval(x), y = eval(y), group = "cyl"))
#this works but, I want to use variables rather than the actual string.
hchart(mtcars, "point", hcaes(x = "mpg", y = "hp", group = "cyl"))
#The output I would like to see is
x = "mpg"
y = "hp"
hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))
答案 0 :(得分:0)
x = "mpg"
y = "hp"
# x = enexpr(x) you may want to use that, not mandatory
# y = enexpr(y) you may want to use that not mandatory
hchart(mtcars, "point", hcaes(x = !! x, y = !! y, group = "cyl"))
此代码应该有效