我正在使用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"))
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"))
这段代码应该有效